it does not work... anyway here is the code Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class InventorySystem : MonoBehaviour { public static InventorySystem Instance { get; set; } public GameObject inventoryScreenUI; public bool isOpen; public List<GameObject> slotList = new List<GameObject>(); public List<string> itemList = new List<string>(); private GameObject itemToAdd; private GameObject whatSlotToEquip; //public bool isFull; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } } void Start() { isOpen = false; PopulateSlotList(); } // it makes it so i dont need to drag and drop the slots to the slotlist [DOES WORK NOW] private void PopulateSlotList() { foreach (Transform child in inventoryScreenUI.transform) { if (child.CompareTag("Slot")) { Debug.Log("slotlist is working"); slotList.Add(child.gameObject); } } } // makes it so i can open the inventory void Update() { if (Input.GetKeyDown(KeyCode.E) && !isOpen) { Debug.Log("E is pressed"); Cursor.lockState = CursorLockMode.None; inventoryScreenUI.SetActive(true); isOpen = true; } else (Input.GetKeyDown(KeyCode.E) && isOpen); { Cursor.lockState = CursorLockMode.Locked; inventoryScreenUI.SetActive(false); isOpen = false; } void AddToInventory(string itemName) { isFull = true; Debug.Log("inventory is full"); whatSlotToEquip = FindNextEmptySlot(); itemToAdd = Instantiate(Resources.Load<GameObject>(itemName), whatSlotToEquip.transform.position, whatSlotToEquip.transform.rotation); itemToAdd.transform.SetParent(whatSlotToEquip.transform); itemList.Add(itemName); } } CheckIsFull(); { isFull =true; int counter = 0; foreach (GameObject slot in slotList) { if (slot.transform.childCount >0) { counter == 1; } } if (counter == 21); { return true; } else { return false; } } FindNextEmptySlot(); { foreach(GameObject slot in slotList) { Debug.Log("2"); if (slot.transform.childCount == 0) { Debug.Log("working 2"); return slot; } } return new GameObject(); } }
You get a lot of errors but don't say what they are. You say it does not work but do not say what it's supposed to do when it does nor what doesn't work. Please put some effort into describing what it is you want devs to look at. Thanks.
I can imagine some of the errors with that code, that won't compile. I'd say the start would be to do some base tutorials on C#.