evelynshilosky

CraftingSystem - Part 7

Jun 2nd, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class CraftingSystem : MonoBehaviour
  7. {
  8.  
  9.     public GameObject craftingScreenUI;
  10.     public GameObject toolsScreenUI;
  11.  
  12.     public List<string> inventoryItemList = new List<string> ();
  13.  
  14.     //Category Buttons
  15.     Button toolsBTN;
  16.  
  17.     //Craft Buttons
  18.     Button craftAxeBTN;
  19.  
  20.     //Requirement Text
  21.     Text AxeReq1, AxeReq2;
  22.  
  23.     public bool isOpen;
  24.  
  25.     //All Blueprints
  26.  
  27.  
  28.  
  29.     public static CraftingSystem Instance { get; set; }
  30.  
  31.  
  32.     private void Awake()
  33.     {
  34.         if (Instance !=null && Instance !=this)
  35.         {
  36.             Destroy(gameObject);
  37.         }
  38.         else
  39.         {
  40.             Instance = this;
  41.         }
  42.     }
  43.  
  44.  
  45.     // Start is called before the first frame update
  46.     void Start()
  47.     {
  48.  
  49.         isOpen = false;
  50.  
  51.         toolsBTN = craftingScreenUI.transform.Find("ToolsButton").GetComponent<Button> ();
  52.         toolsBTN.onClick.AddListener(delegate { OpenToolsCategory(); });
  53.  
  54.         // AXE
  55.         AxeReq1 = toolsScreenUI.transform.Find("Axe").transform.Find("req1").GetComponent<Text>();
  56.         AxeReq2 = toolsScreenUI.transform.Find("Axe").transform.Find("req2").GetComponent<Text>();
  57.  
  58.         craftAxeBTN = toolsScreenUI.transform.Find("Axe").transform.Find("Button").GetComponent<Button>();
  59.         craftAxeBTN.onClick.AddListener(delegate { CraftAnyItem(); });
  60.  
  61.     }
  62.  
  63.    
  64.     void OpenToolsCategory()
  65.     {
  66.         craftingScreenUI.SetActive (false);
  67.         toolsScreenUI.SetActive (true);
  68.     }
  69.  
  70.  
  71.     void CraftAnyItem()
  72.     {
  73.  
  74.         //add item into inventory
  75.  
  76.  
  77.         //remove resources from inventory
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.     }
  85.  
  86.  
  87.  
  88.     // Update is called once per frame
  89.     void Update()
  90.     {
  91.         if (Input.GetKeyDown(KeyCode.C) && !isOpen)
  92.         {
  93.  
  94.             craftingScreenUI.SetActive(true);
  95.             Cursor.lockState = CursorLockMode.None;
  96.             isOpen = true;
  97.  
  98.         }
  99.         else if (Input.GetKeyDown(KeyCode.C) && isOpen)
  100.         {
  101.             craftingScreenUI.SetActive(false);
  102.             toolsScreenUI.SetActive(false);
  103.             if (!InventorySystem.Instance.isOpen) {
  104.                 Cursor.lockState = CursorLockMode.Locked;
  105.             }
  106.             isOpen = false;
  107.         }
  108.  
  109.  
  110.  
  111.     }
  112. }
Add Comment
Please, Sign In to add comment