public class InventoryUI : MonoBehaviour
{
public Transform itemsParent;
Inventory inventory; // Our current inventory
InventorySlot[] slots;
void Start()
{
inventory = Inventory.instance;
inventory.OnItemChangedCallback += UpdateUI;
slots = GetComponentsInChildren();
}
void Update()
{
{
// Loop through all the slots
for (int i = 0; i < slots.Length; i++)
{
if (i < inventory.items.Count) // If there is an item to add
{
slots[i].AddItem(inventory.items[i]); // Add it
}
else
{
// Otherwise clear the slot
slots[i].ClearSlot();
}
}
}
void UpdateUI () {
Debug.Log("UPDATING UI");
}
}
}
↧