using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class InventoryDisplayer : MonoBehaviour { [SerializeField] private Inventory inv; [SerializeField] private GameObject slotPrefab; [SerializeField] private GameObject gridGameObject; private List<SlotController> slots = new List<SlotController>(); void Awake() { Debug.Log("Started inventory"); UpdateInventory(); } public void UpdateInventory() { int currentId = 0; foreach (SlotController s in slots) Destroy(s.gameObject); slots = new List<SlotController>(); foreach (Item i in inv.inventory) { slots.Add(Instantiate(slotPrefab, gridGameObject.transform).GetComponent<SlotController>()); slots[currentId].item = i; i.slotId = currentId; currentId++; } } private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { gameObject.SetActive(false); } } }