Component Class Hierarchy

I’ve created a hierarchy of UnityScript classes.

SuperClass
   SubClassA extends SuperClass
   SubClassB extends SuperClass

These are currently stand-alone classes that I instate in code. I’d now like to map them so each one is a Component.

The problems seems to be that they all need to inherit directly from MonoBehavior.

Is it possible for my SuperClass to inherit from MonoBehavior, and the subclasses to inherit from the SuperClass ?

If it’s not possible in UnityScript, would this be possible in C# ?

It should also be possible in UnityScript that way:

class SuperClass extends MonoBehaviour
{
    
}

class SubClassA extends SuperClass
{
}

class SubClassB extends SuperClass
{
}

Note that every class have to be in it’s own file and the file name has to match the class name. Otherwise you can’t add the scripts to a GameObject.

I use C# exclusively because i don’t like the JS-syntax :wink: Also C# allows to inherit from one base-class and from additional interfaces whereas UnityScript only allows one ancestor. Also i don’t have a clue of the virtual / override syntax in UnityScript which is actually one of the most important things when you use inheritance.

In C# you would do something like that:

public class SuperClass : MonoBehavior
{
    protected virtual void Update()
    {
    }
}

public class SubClass : SuperClass
{
    protected override void Update()
    {
        base.Update(); // call the inherited function Update() from SuperClass
    }
}

Yes it is possible in c#

SuperClass : MonoBehavior
{
  ...
}

SubClass : SuperClass
{
   void Update()
   {...}
   //etc.
}