Im struggling with my inventory yet again.
I’ve got everything pretty much working now equipping items, dropping them etc
But say if I have my inventory with 3 items
EXAMPLE
[X X X X] ← empty
[1 2 3 X] ← three items
[1 X 3 X] ← now i drop item 2 or equip it
[1 X 3 4] ← then i pickup item 4 it isnt placed into the inventory at the null object its added to the end
This is my pickup item function
function pickUpItem(itemid:int){
for( var iii : int = 0; iii < invSlots.childCount; iii++ ) {
if((invArray[iii] == 0 || "" || null) && !pickedUpItem){
pickedUpItem=true;
invArray[iii]=itemid;
Debug.Log("INVARRAY: " + invArray[iii]);
invSlotsob[iii].gameObject.GetComponent(Image).sprite = targetItem.GetComponent(item).SPR;
invSlotsob[iii].gameObject.GetComponent(slot).itemEquippable = targetItem.GetComponent(item).equippable;
if(targetItem.GetComponent(item).equippable == true){
invSlotsob[iii].gameObject.GetComponent(slot).equipSlot = targetItem.GetComponent(item).equipSlot;
}
updateSlots();
Destroy(targetItem);}
}
}
This is the drop item
function DropItem(){
slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(Image).sprite = defaultSlotSpr;
GameObject.FindWithTag("GameSettings").GetComponent(itemdb).DropItem(slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id);
slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id = 0;
player.GetComponent(inventory).updateSlots();
slotMenu.SetActive(false);
}
This is the equip code
function EquipItem(){
if(itemEquippable == true){
switch (equipSlot)
{
case 5:
print ("Why hello there good sir! Let me teach you about Trigonometry!");
break;
case 4:
print ("Hello and good day!");
break;
case 3:
print ("Whadya want?");
break;
case 2:
player.GetComponent(equipment).shoulders = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id;
eShoulders.GetComponent(Image).sprite = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(Image).sprite;
break;
case 1:
player.GetComponent(equipment).chest = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id;
eChest.GetComponent(Image).sprite = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(Image).sprite;
break;
case 0:
player.GetComponent(equipment).head = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id;
eHead.GetComponent(Image).sprite = slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(Image).sprite;
break;
default:
print ("Incorrect intelligence level.");
break;
}
slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(slot).id = 0;
slotMenu.GetComponent(dropButton).selectedSlot.GetComponent(Image).sprite = defaultSlotSpr;
player.GetComponent(inventory).updateSlots();
slotMenu.SetActive(false);
}
}