Possible to inherite script?

A simple quastion: Is it possible to inherite a script with javascript and then overload functions?

1 Answer

1

Yup you can:

class A //this can extend MonoBehaviour if you need it to work as a script
{
    function Moo() { }
}

class B extends A
{
    function Moo() { } //overrides A's version
}

You can't overload variables - use a function to get/set it instead. Check my answer here - http://answers.unity3d.com/questions/45879/can-i-declare-properties-in-js for a nice way to do it

try the keyword override on the variable in the derived class

overload != override. I don't really use Unityscript but i guess you also have to make the function virtual to be able to override it. Without making it virtual you don't override it. You just reimplement it and hide the inherited function. That would totally destroy the advantange of inheritance ;)