Hello,
I’ve been studying Unity for a while now, and I’m familiar with OOP, have made little games with my own Classes in other languages, etc. I’m still having trouble figuring out the best approach for this situation, and Google searches for examples or tutorials have been unsuccessful (most tutorials are really basic, or focus on the editor side, instead of the scripting side).
So here’s my scenario:
Every time the Player uses an item that is already equipped, I want to call something like a “gameobject.Item.Use()” method. The problem is that I want to have different kinds of items, like Keys or Guns, but I want them all to inherit from a base 'Item" Class, like this:
- Class Item
- Class ItemKey Inherits Item
- Class ItemGun Inherits Item
Creating the classes is easy, but how do I go about “adding” these to an existing gameobject? Can I create a script that extends another script, since all scripts are classes that extend MonoBehavior (as far as I understand)? If yes, how? Sorry if the question sounds basic, I understand most of the concepts involved, I’m just having trouble putting it all together.
I’d love to see links for tutorials or examples of different ways to organize / structure scripting in a real world scenario.
It may be worth mentioning that I DON"T want to create everything in scripting, since that kinda defeats the point of using Unity for me, I want to have a blend of creating and managing objects in the editor, and just assigning scripts as i go.
Thanks!
Leo.
P.S. I’m using UnityScript.