Hey guys, small problem here:
I have an interface script called Item.
Then I have many scripts called RedPotion, BluePotion, Boots, etc.
I am attaching the above scripts to empty game objects to use in an inventory system.
I use this:
GameObject.GetComponent();
I know that will give me the RedPotion script. The problem is that since its going to be an array of gameobjects, that object may not have a RedPotion script, it may have a BluePotion script, or Boot script, etc. Now, as I said earlier, they all implement the “Item” interface. If I use:
GameObject.GetComponent();
will that work? Will it pick up the script that implements Item, or does it look for a component called Item?
Sorry if i explained it badly, its hard to put this stuff into words.
It will work, but Unity is not great with interfaces. Specially when trying to assign them in the editor. So if possible, use abstract classes instead.