using UnityEngine; using System.Collections.Generic; //Allow for lists to be used using TMPro; using Unity.VisualScripting; public class PlayerInventory : MonoBehaviour { public List inventory = new List(); //Create a list to store inventory items public TextMeshProUGUI inventoryText; public GameObject inventoryPanel; private bool currentlyActive = false; private void Start() { inventoryPanel.SetActive(false); inventoryText.gameObject.SetActive(false); } public void AddItem(string itemName) //Allow other scripts to add items to the inventory { inventory.Add(itemName); if (currentlyActive) { UpdateInventoryUI(); } } private void UpdateInventoryUI() //Method that updates my inventory UI { inventoryText.text = ""; foreach (string item in inventory) { inventoryText.text += item + "\n"; } } public void DisplayInventory() //Display the inventory in the ui { if (currentlyActive == true) { inventoryPanel.SetActive(false); inventoryText.gameObject.SetActive(false); currentlyActive = false; } else { inventoryPanel.SetActive(true); inventoryText.gameObject.SetActive(true); UpdateInventoryUI(); currentlyActive = true; } } }