JS Delegates

Hey guys,
Can someone please point me in the right direction to get delegates and events to work in JavaScript/UnityScript? I usually program in C#/C++ but for this project we’re required to work in JS. I’ve followed Prime31’s youtube video but still cannot get it to work.

Major issues I’m having is issues with unity not recognising the “delegate” and “event” tokens.
Even trying to simplify it down to just having a function, and a static variable of that function as a type Unity still gives an unexpected token error message.


As far as i know you have to use the “usual” Javascript syntax (the type “Function” with a capital F). As you might know even UnityScript is compiled to a .NET / Mono dll. UnityScript is not a standardized language and i only use C# for Unity so i can’t tell the exact syntax but i think i can remember a question about that issue and it wasn’t that difficult.

I would try something like:

var myDelegate : Function(parameter : float);

but haven’t tested it yet :wink: