Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Colectible Inventory / InventoryDisplayer.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class InventoryDisplayer : MonoBehaviour
  6. {
  7. [SerializeField] private Inventory inv;
  8. [SerializeField] private GameObject slotPrefab;
  9. [SerializeField] private GameObject gridGameObject;
  10. private List<SlotController> slots = new List<SlotController>();
  11. void Awake()
  12. {
  13. Debug.Log("Started inventory");
  14. UpdateInventory();
  15. }
  16. public void UpdateInventory()
  17. {
  18. int currentId = 0;
  19. foreach (SlotController s in slots) Destroy(s.gameObject);
  20. slots = new List<SlotController>();
  21. foreach (Item i in inv.inventory)
  22. {
  23. slots.Add(Instantiate(slotPrefab, gridGameObject.transform).GetComponent<SlotController>());
  24. slots[currentId].item = i;
  25. i.slotId = currentId;
  26. currentId++;
  27. }
  28. }
  29. private void Update()
  30. {
  31. if (Input.GetKeyDown(KeyCode.Escape))
  32. {
  33. gameObject.SetActive(false);
  34. }
  35. }
  36. }