private void addToInventory(BlockInfo blockInfo) { GameObject thisSlot = null; foreach (Transform child in inventoryContainer.transform) { if (child.gameObject.GetComponent <BlockInfo>() != null) { if (child.gameObject.GetComponent <BlockInfo>().block == blockInfo.block) { thisSlot = child.gameObject; break; } else { continue; } } } if (thisSlot == null) { foreach (Transform child in inventoryContainer.transform) { if (child.gameObject.GetComponent <InventorySlot>().isOccupied == false) { thisSlot = child.gameObject; break; } else { continue; } } } inventoryContainer.addClassToSlot(blockInfo, thisSlot); }