mardi 3 novembre 2015

Getting properties of derived type on a Gameobject

So i have several gameobjects in me scene which represent different actors. Also, I have scripts to for each type of actor, and they all derive from 'Actor' script.

public class Actor : MonoBehaviour {

//some properties

}

///

public class Doctor : Actor {

//some more properties

}

only the derived scripts are attached to the gameobjects. i.e. if i have a doctor gameobject- only the 'Doctor' script is attached to it in the inspector.

My code runs through all these actor gameobjects- and updates their properties (base + derived) from some data input. Currently im checking every gameobject if he has the specific component and then get the properties from the right script.

My objective is to ALWAYS get the properties declared by derived class from 'Actor', that is currently attached to the gameobject, without looking for the component. I would think something in Linq will do the trick.





Aucun commentaire:

Enregistrer un commentaire