private void CreateInventorySlotsAndItems(List <InventoryItemData> inventoryData) { // Create as many slots as needed, round up if odd int numSlotsCreated = inventoryData.Count % 2 == 0 ? inventoryData.Count : inventoryData.Count + 1; for (int i = 0; i < numSlotsCreated; i++) { // Skip dummy slots if (i >= inventoryData.Count) { break; } // Create the inventory slot GameObject slotGO = GameObject.Instantiate(InventorySlotPrefab); slotGO.transform.SetParent(InventorySlotContainer); slotGO.transform.localScale = Vector3.one; InventorySlot slot = slotGO.GetComponent <InventorySlot>(); _inventorySlots.Add(slot); // Create the inventory item GameObject itemGO = GameObject.Instantiate(InventoryItemPrefab); // Initialize the item InventoryItem item = itemGO.GetComponent <InventoryItem>(); item.Initialize(inventoryData[i]); // Accept the item into the slot slot.AcceptInventoryItem(item); } }