Hello! I’m new to game dev; sorry for my ignorance here…
I’m trying to implement an inventory system in my game and I want to allow a user to “use” an item on another item. Online I’ve found tutorials that say to make a function that checks the item type then handles the interaction.
But is it possible to somehow use an interface with a “use on” method to be implemented so I don’t have to run a switch/if check for all possible items? This way I could just call the method on the item I’m using.
I tried adding an interface to my item struct and it allowed me to, but I can’t set the implementing class in the data table that implements the item struct. Is this impossible? Am I just doing this all wrong?
EDIT: It seems like this probably won’t work. I’m probably going to use a switch/if statements to handle this. Is there a better way though?