I have a Motor script that needs to call a Motion function from one of several types of Motion classes. So basically, one type of character might use the standard Motion script, while another character might use a SuperSpeed motion script that overrides the standard Motion class's main Motion function.
How can I tell my Motor class which type of Motion class to use?
asked Jun 25 '11 at 06:50 PM
It sounds like you want a virtual function.
and here's an example of the implementation:
Virtual functions shouldn't be confused with
Virtual calls have a small performance decrease but it usually won't matter.
I would avoid where it's possible the use of inheritence in Unity because Unity uses the component pattern. Is it not possible for you to define public fields in your motion script that would change its behaviour (e.g. MAxAcceleration, MaxSpeed, ...)? There are several advantages in using public field:
answered Jun 26 '11 at 08:02 AM