- Home /
Question by
Toxic Blob · Jan 30, 2011 at 05:03 PM ·
coroutineyieldstate
Tracking state changes using yield
I have a function which I use to change the enum state of my character. When the state changes I set stateJustChanged
to true, then use yield
to wait one frame before turning stateJustChanged
to off. Which normally works fine. Unless on that second frame I again change state, in which case stateJustChanged
remains off, not registering that the state has just changed.
Also, sometimes the state change isn't registered right away...
Is there a better way of doing this?
public var state:CharacterState = CharacterState.Off;
public var stateJustChanged:boolean;
function ChangeState(newState:CharacterState)
{
state = newState;
stateJustChanged = true;
yield;
stateJustChanged = false;
}
Comment