Complete the code to declare an enum for AI states.
public enum AIState { Idle, [1], Attack }The enum AIState defines different states for the AI. 'Patrol' is a common state between Idle and Attack.
Complete the code to set the initial AI state to Idle.
private AIState currentState = [1];The AI starts in the Idle state, so we assign currentState to AIState.Idle.
Fix the error in the switch statement to handle the AI states correctly.
switch (currentState) {
case AIState.Idle:
IdleBehavior();
break;
case AIState.Patrol:
[1]();
break;
case AIState.Attack:
AttackBehavior();
break;
}For the Patrol state, the method PatrolBehavior() should be called to define its behavior.
Fill both blanks to update the AI state from Idle to Patrol when a condition is met.
if (currentState == [1] && seesEnemy == false) { currentState = [2]; }
The AI changes from Idle to Patrol when it does not see an enemy.
Fill all three blanks to create a dictionary mapping AI states to their behavior methods.
private Dictionary<AIState, Action> stateActions = new Dictionary<AIState, Action>() {
{ [1], IdleBehavior },
{ [2], PatrolBehavior },
{ [3], AttackBehavior }
};The dictionary links each AIState to its corresponding behavior method.