Creating a new Contains method to find objects of a specific type

Hey everyone!

I found it super awesome that people here are really supportive to new game developers. I have a small question about creating new Contain methods for data structures other than primitive data types. I’ll try my best to explain what I mean, I’ve created a Scriptable Object called Item that I want to add to my game. The new method I wanted to incorporate was ContainsItem to check if my inventory contains a specific Item.

I was hoping to call ContainsItem to an array of Items, Item, but it gives me this error.

How do I resolve an issue like this? Thanks in advanced!

But your ‘Item’ class has the ContainsItem method not your Inventory while it should be in ‘Inventory’ object.
Why would an Item should look for itself if it’s in a certain inventory?

Ah okay, so instead of declaring it in my Item class I’ll try creating a separate Inventory class to use an Item[ ] to store all the player’s items, and move ContainsItem to my new Inventory class.

1 Like