Hello, I have the following code:
for(int i = 0; i < slots; i++)
{
if(inventory *== GameObject.Find("Key"))*
- {*
_ inventory = null;_
* //inventory[i - 1] = null;*
* openDoor = true;*
* break;*
* }*
}
This code iterates through an array to check if the player has the key, if the player does have the key, the index changes to a null value and the door is opened.
The problem is, if the variable i is at 1 for example, and the player has the key, when inside the if statement the third element (2) is changed, instead of the second one (1).
I don’t know if I’m making myself clear, and I apologize for my english.
Thanks.
Maybe try altering the check so it looks for the name rather than the actual object and see what happens? e.g.
if(inventory*.name == "Key")*