How to make a locked door that opens with a key thats in my array?

I Have an inventory system i made using arrays, how would i make a locked door that only opens up when i have a key item inside of my inventory array?

Simply, give a name or ID for the key. When you enter to the trigger box near the door, check it weather you have the key or not.

Well how would i give it a name or ID? And after i give it an ID how would i get a refference to the item inside of my array? Thanks for the reply btw

Normaly your Inventory should consist of an array that stores information of your items.
Like a name, a value, a texture or what ever you need. You don’t really have an object
stored in your inventory. This is because you can’t store items as a real object and also
delete them in the scene. The references of deleted object will also be deleted after 60
second. So you just need to save the values that your item had. I used a struct in my
item for all the values and made an array of that struct for my player too, so he can store
those values.

So if your inventory is fully functioning, you should be able to just go through it with a for loop and check for certain values like the ID that yRezaei mentioned.

PS: Also, i don’t know what your inventory system is like. Is it an RPG like one where you can pickup and drop items?
Than you would need to have a few arrays. One for the values, mentioned above, one where you store all items by hand and one where you store the indices of the second array. So if you have the key in the second array at index 0
and you have this key now in your real inventory at index 5, there would be an int array that as the 0 at index 5 and the values array that has all the values at index 5 too.
Now if you spawn the item back to the world, you would just look up the index (0) and get this from the second array which contains the classes. Now you just spawn the class. The new spawned object gets all the values back and you delete everything from the inventory.

It also would be wise to create an enum of item types and make sure all your items are correctly. Iterate through your array, check each for type Key. If type Key == true, check key ID. If Key ID == Door ID, unlock door. It is also useful to have a bool to set the doors lock status. That way, you can save a few cycles when the player gets to a door that is already unlocked.