/// <summary> /// Creates UI item, plays its "get" animation and adds it to list of active UI items /// </summary> /// <param name="key">Item to create a UI item from</param> public void AddItem(InteractableItemKey key) { // If slot already exists, make that item fill the slot foreach (InventoryItemUI slotItem in slotItems) { if (slotItem.itemKey == key) { slotItem.PlayItemGetAnimation(); activeItems.Add(slotItem); slotItems.Remove(slotItem); return; } } // else create new item and immediately fill the slot GameObject item = Instantiate(itemPrefab, itemParent); InventoryItemUI itemUI = item.GetComponent <InventoryItemUI>(); if (itemUI == null) { Debug.LogError("Item prefab in InventoryUI does not have a InventoryItemUI component"); Destroy(item); } else { itemUI.Init(key); itemUI.PlayItemGetAnimation(); activeItems.Add(itemUI); } }