You could use a enum to list the states of your npc.
Like:
idle,
chase,
attack
Check for the transitions in an Update() function and take the correct action.
This aproach is called Finite State Machine (FSM).
A pseudo code should look like:
enum States{
idle,
chase,
attack
}
States currentState;
Update()
{
switch(currentState)
{
case(States.idle):
BeIdle();
break;
case(States.chase):
Chase();
break;
case(States.attack):
Attack();
break;
}
}
Also don't forget to make the transitions and change the value of "currentState" to the next state.
↧