public int WhichInventorySlot(InventorySlotIcon theSlot) { if (!nPC) { int slotNum = 0; foreach (Image slot in uIInventorySlotsIcons) { if (slot.GetComponent <InventorySlotIcon>() == theSlot) { return(slotNum); } slotNum++; } return(-1); } if (nPC) { int slotNum = 0; foreach (Image slot in uiShopSlotIcons) { if (slot.GetComponent <InventorySlotIcon>() == theSlot) { return(slotNum); } slotNum++; } return(-1); } return(-1); }
public void SwitchBagSlots(InventorySlotIcon firstToSwitch, InventorySlotIcon secondToSwitch) { if (FindSpesificFreeSlot(WhichInventorySlot(firstToSwitch)) == false && FindSpesificFreeSlot(WhichInventorySlot(secondToSwitch)) == false) // Find out if these two slots have anything in them if both dont then do { Item tempItemOne = inventoryItems[WhichInventorySlot(firstToSwitch)]; Item tempItemTwo = inventoryItems[WhichInventorySlot(secondToSwitch)]; RemoveItemFromInventory(null, WhichInventorySlot(firstToSwitch)); print(WhichInventorySlot(firstToSwitch)); RemoveItemFromInventory(null, WhichInventorySlot(secondToSwitch)); AddItemToInventory(tempItemOne, WhichInventorySlot(secondToSwitch)); AddItemToInventory(tempItemTwo, WhichInventorySlot(firstToSwitch)); } if (FindSpesificFreeSlot(WhichInventorySlot(firstToSwitch)) == false && FindSpesificFreeSlot(WhichInventorySlot(secondToSwitch)) == true) // This is if you are moving an item into an empty spot { Item tempItemOne = inventoryItems[WhichInventorySlot(firstToSwitch)]; RemoveItemFromInventory(null, WhichInventorySlot(firstToSwitch)); AddItemToInventory(tempItemOne, WhichInventorySlot(secondToSwitch)); } if (FindSpesificFreeSlot(WhichInventorySlot(firstToSwitch)) == true && FindSpesificFreeSlot(WhichInventorySlot(secondToSwitch)) == true) { print("Fist has nothing to switch"); } }