Multiple inheritance in a Javascript class?

Hi all,

Experimenting with AngryAnt’s Behave add-on to see if it can be used with JavaScript. As mentioned in the documentation for Behave, to make use of the the script you need to make a class which extends “BehaveLibrary.IAgent”. No problem there, just start with:

#pragma strict

class SomeClass extends BehaveLibrary.IAgent { 

.....

However, doing this loses the connection with all those MonoBehaviour goodies, such as yield, destroy, etc. Not to mention all sorts of basic Unity stuff, too. :stuck_out_tongue:

The question, then, is can a JavaScript class in Unity extend multiple classes? Normal JavaScript should be able to accept:

class SomeClass extends MonoBehaviour, BehaveLibary.IAgent {

However, this generates errors:

Does anybody know if multiple inheritance is supported in UnityScript, and if so what the syntax is?

Thoughts/help appreciated!

~D

you can not extend multiple classes, thats not possible independent of the language.

You can extend a single class + abstract classes (“interfaces”) only and that is potentially restricted to C# actually as UnityScript is geared towards simplicity, not feature completeness.

Also you don’t need it actually.
You wouldn’t want the agent to be a monobehaviour, you would want the agent to store a game object reference, the game object which is driven by its behaviour to be precise.

Ah, forgive my sloppy terminology.

But I think I’ve got the clue now to get this doing what I want it to…

Thanks,

~D

I would recommend to start with the sample to see and understand how it works

If you did need to, you could do so such as this:

class Apple extends ICollectable implements IEatable { … }

Why would you want to extend an interface?

That’s what I asked myself

Since ICollectable and IEatable are both interfaces, this should probably be:

class Apple implements ICollectable, IEatable { ... }

i think you need the implements key word as in:

class SomeClass extends MonoBehaviour implements BehaveLibary.IAgent