- Home /
storing scripts that implements an interface
I have a scriptable object set up to store all information on the items in my game, however some of my items will be usable and i still want to store them in my scriptable object. I made an interface called IUsable and i hoped i could somehow reference scripts that implemented that interface in my item class, something along the line of
Public IUsable Scriptiwanttostore
so i could just make a script for each item which could be used and then use that script as a variable for each.
is there a way to do this? or should i go about it in another way?
Not sure whether it's just me, but your question seems a little unclear.
Wouldn't the declaration you've written type Scriptiwanttostore as a seperate instance of your interface IUsable? I'm not sure why you'd want to do that.
The way I'm reading your question is that you want a container to store a reference to all objects, whether they have been used or not. If that's the case, the following link is a great reference:
http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type
If you're asking something else, you might want to re-word the question.
Dan
im sorry if it was worded poorly, what im trying to achieve is a way to call diffrent functions, depending on which item i use, basicly i want an effect on each diffrent item i use, how should i store these diffrent functions, so they are connected with my diffrent items?
You could create a Class called Item to store common properties like name, inventorySprite, value and so on. Then create other classes for Armour, Weapon, Potion and so on which inherit from Item. Each of the Armour/Weapon/Potion etc could have their own functions. You could then have a list or array of type Item to hold all the objects you create.
This would allow you the flexibility to create a +2 Bronze Broadsword of Goat Herding, different health potions, plate mail, chain mail, scale mail, leather jerkins and so on.
I'm still not sure I'm answering your question properly? Can you tell me what items you're using and what actions you want the functions to carry out?
Dan