|
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? Example:
and....
Will this ever work? It seems like Thing's DoStuff() is completely ignored. I'm probably missing something.
(comments are locked)
|
|
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 e.g. See, I knew I was missing something :) Thanks a lot Mike, just what I was looking for.
Sep 27 '10 at 02:34 AM
alpine 2
(comments are locked)
|
|
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.
(comments are locked)
|
