Skip to content

Instantly share code, notes, and snippets.

@xdegtyarev
Created August 5, 2014 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdegtyarev/f74fba5be2dd07be1364 to your computer and use it in GitHub Desktop.
Save xdegtyarev/f74fba5be2dd07be1364 to your computer and use it in GitHub Desktop.
FSM Example 1
enum State {
CHARGING,
SEARCH_HUMANS,
KILL_ALL_HUMANS
}
State myState = State.CHARGING;
float charge = 0f;
void Update() {
switch ( myState ) {
case State.CHARGING:
if ( charge == 100f ) {
myState = State.SEARCH_HUMANS
} else {
DoCharge();
}
break;
case State.SEARCH_HUMANS:
if ( isHumansDetected() ) {
myState = State.KILL_ALL_HUMANS
} else {
SearchHumans();
}
break;
case State.KILL_ALL_HUMANS:
if ( allHumansIsDead() ) {
myState = State.CHARGING;
} else {
KillHumans();
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment