#pragma strict
var in_action: boolean;
var action: function(): IEnumerator = coroutine;
function Update () {
if(in_action)
return;
in_action = true;
enter_phase();
}
function enter_phase() {
Debug.Log("entering action");
yield action();
in_action = false;
}
function coroutine () {
Debug.Log("in coroutine");
yield WaitForSeconds(1);
}
If I comment out the “yield WaitForSeconds(1)” the code works and I see “in coroutine” in the debug log. However, if I put it in, I can’t see it anymore. For some reason, I can’t properly call coroutines through pointers or Function classes in UnityScript (but I can call normal functions). How can I get the functionality I want?
P.S. I realize I can just write:
yield coroutine();
but I want to be able to have this AIBase be a base class where the actions are set by the derived classes.
UnityScript does allow you to create and call function references, with the Function type (note big F):
#pragma strict
function Start() {
var myFunc : Function;
myFunc = Test;
myFunc();
var myFuncWithArg : Function;
myFuncWithArg = TestWithArg;
myFuncWithArg(6);
}
function Test() {
Debug.Log("Test successful");
}
function TestWithArg(arg : int) {
Debug.Log("You're thinking of the number " + arg);
}
One downside with the above: I don’t know if there’s a way to force compile-time checking of the types you’ll pass to those functions, like you can get in C#.