Resetting inventory so when item picked up goes to first empty slot

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);
}



}

I don’t know too much but would it perhaps be a Generic List: http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type

I’m not sure though if having items 1234 and removing 24 would then place the next one at (former) position 2 or shift 3 up to what was 2 and add the new one to what was 3. Should be easy enough to test though.

I changed my inventory so that it now searches for the first empty slot and fills that :slight_smile:
I managed to figure out a few other bugs will doing it aswell!

Thank you for your help though going to check it out now see if I can make it better with that

Not really sure how much help it was, but good luck with it :slight_smile: