FSM and coroutine problem

Hi,

I am coding a Javascript finite state machine based on and adapted from the C# FSM framework found at the unity wiki. I am trying to add a delay so the animation ends before changing to another state but I obtain the next error:

Assets/Scripts/example.js(192,18 ) BCE0101: Return type ‘void’ cannot be used on a generator. Did you mean ‘IEnumerator’? You can also use ‘System.Collections.IEnumerable’ or ‘object’.

The script es called example and it has all the state class implementations (Idle, Run, Turnaround,…)

Any ideas?

Thanks

class Turnaround extends FSMState {
	function Turnaround() {
		stateId = StateId.turnaround;
	}
	
	function Reason(player : GameObject) {
		yield player.GetComponent(example).StartCoroutine(player.GetComponent(example).wait(1));
		player.GetComponent(example).SetTransition(Transition.turnaroundIdle);
	}
	
	function Action(player : GameObject) {
		player.GetComponent(example).aniSprite(16, 6, 0, 5, 5, 16);
	}
}

function wait(waitTime : float) {
	yield WaitForSeconds(waitTime);
	
}

This looks related:

Not sure of the why, but it seems that your wait function needs to explicitely return an IEnumerable type, possibly due to it being in a subclass.

So declare your wait function like this:

function wait(waitTime : float) : IEnumerable
{
  yield WaitForSeconds(waitTime);
}

Hi Dracorat, I want to invoke the coroutine wait() and wait until it is completed. After that, I want to execute the next line: (player.GetComponent(example).SetTransition(Transition.turnaroundIdle).

Something like the second example of the Script Reference link text.
I have add Debug.log("in wait coroutine") in the wait coroutine and the message is never printed…

Thanks in advance