- Home /
Question by
DannyB · Jun 20, 2012 at 06:33 PM ·
coroutineyieldstate-machinefunction-type
Yield on a Function Typed Variable
Hello everybody,
I am experimenting with a simple state machine, and today was more or less the first time I wrote the word "yield", so coroutines is a completely new concept to me.
I was hoping to call a function-typed variable, but could not make it work. Below are some code snippets, if the entire code is needed, I can update the post (I hope, first time poster...).
These three attempts of mine are inside a function StateMachine() that I call from my Start() function. The first two work, the last one does not. Can anyone help me spot the problem?
Thanks.
// Working
while( true ) {
switch( state ) {
case State.MovingUp: yield StateMovingUp(); break;
case State.MovingDown: yield StateMovingDown(); break;
}
yield;
}
// Working, not sure is the correct way
while( true ) {
var act : String = "StateDoNothing";
switch( state ) {
case State.MovingUp: act = "StateMovingUp"; break;
case State.MovingDown: act = "StateMovingDown"; break;
}
yield StartCoroutine( act );
}
// Not working (nothing happens, no error)
while( true ) {
var act : Function = StateDoNothing;
switch( state ) {
case State.MovingUp: act = StateMovingUp; break;
case State.MovingDown: act = StateMovingDown; break;
}
yield act();
}
Comment