Suppose I have two classes. One is a base class extending from MonoBehaviour. We'll call it Base. There's a method in this class called DoStuff(), which is called at various points in Update. I have a second class called Thing that extends from Base. What I'm wondering is, can I override the DoStuff() method in Thing so that when it's called via the base class, the derived method is used?
Will this ever work? It seems like Thing's DoStuff() is completely ignored. I'm probably missing something.
You need to make both versions of DoStuff virtual, which means that when DoStuff is called, it'll look for most specific version of the function
As it is now, they're both completely different functions with the same name, so from Update, DoStuff references the base class's version, not your extending class
answered Sep 27 '10 at 01:39 AM
This will work yes. But you have to cast it to class Thing, otherwise its considered class base and the function of class base will be called.
The redeclaration in the extended class does not make it go away in the base class.
answered Sep 26 '10 at 10:38 PM