public void OnDrop(PointerEventData eventData)
{
GameObject dropped = eventData.pointerDrag;
InventoryItem inventoryItem = dropped.GetComponent();
InventorySlot slot1 = inventoryManager.inventorySlot1Object;
InventorySlot slot2 = inventoryManager.inventorySlot2Object;
InventoryItem itemInSlot1 = slot1.GetComponentInChildren<InventoryItem>();
InventoryItem itemInSlot2 = slot2.GetComponentInChildren<InventoryItem>();
//Item Slot 1
if (transform.childCount > 0 && itemInSlot1.item == inventoryItem.item)
{
itemInSlot1.count++;
}
//Item Slot 2
if (transform.childCount > 0 && itemInSlot2.item == inventoryItem.item)
{
itemInSlot2.count++;
}
}
My intention is to repeat this many times, but I wanted to know if there is any way to reduce this. Because they do the same thing:
//Item Slot 1
if (transform.childCount > 0 && itemInSlot1.item == inventoryItem.item)
{
itemInSlot1.count++;
}
//Item Slot 2
if (transform.childCount > 0 && itemInSlot2.item == inventoryItem.item)
{
itemInSlot2.count++;
}
}