Let's say I have a base class like 'animal' and 3 subclasess like 'dog', 'cat', 'bird' Let's say the base has a function 'speak' that all 3 subclasses implement (bark, meow, chirp).
Then these get added to prefabs.
Now, I'd like to have a script be able to access the script component and call 'speak' and whatever the subclass happens to be, it will make the corresponding sound. Follow?
So, can I just call gameObj.GetComponent(Animal).speak() ?? I would think Unity expects the exact class name (subclass), or GetComponent will fail.
asked Aug 19 '10 at 09:01 PM
In short I believe it (
I've got a Component Damageable that extends Monobehaviour. From that I have 2 components that extend from Damageable. DroneHealth and ShipHealth.
DroneHealth and ShipHealth are attached to prefabs. In my collision test code I do
To get the component (the DroneHeralth or ShipHealth component that is, I never attach the Damageable component to anything).
I then call applyDamage, which has the signature
Bare bones versions of the components
answered Aug 19 '10 at 11:21 PM