The question is answered, right answer was accepted
pick up item while inventory is empty
so i make an array with 4 empty slots when the game starts and the slots are empty to begin with, i want to make it so when i walk onto an item it picks it up and adds it into 1 of the 4 slots however it only works when i try pick up the first item and all slots are empty, once any of the slots are filled it doesn't do anything. also if i then empty the slots after filling any of them is stops working also. i have tried to do this with a for loop and did the same thing so now i have simplified the code to just print the out comes and tried to do it as basic as possible with simple if function however the result is still the same.
void OnCollisionEnter2D(Collision2D col){
if(col.gameObject.name == pickUp.name){
if (invent [0] == null) {
print ("slot1 Empty"); //this works until any slot is filled or if filled and emptied
} else if (invent [1] == null) {
print ("Slot 2 empty");
} else if (invent [2] == null) {
print ("slot 3 empty");
} else if (invent [3] == null) {
print ("Slot 4 empty");
}
}
}
Hard to tell what the issue might be without the rest of the class. I can't see anything obvious, but I'd ask:
Are you sure (col.gameObject.name == pickUp.name) is still true when a slot is filled?
Are you sure filling one slot isn't accidentally filling all of them?
EX: How does your slot-filling code look? Where are pickUp and invent declared and how are they updated?