Game Development Reference
In-Depth Information
05 CurrentState = AI_ENEMY_STATE.CHASE;
06
07 //Set Chase State
08 ThisAnimator.SetTrigger((int) AI_ENEMY_STATE.CHASE);
09
10 //Loop forever while in chase state
11 while(CurrentState == AI_ENEMY_STATE.CHASE)
12 {
13 //Set destination to player
14 ThisAgent.SetDestination(PlayerTransform.position);
15
16 //If we lose sight of player, keep chasing
17 if(!CanSeePlayer)
18 {
19 //Begin time out
20 float ElapsedTime = 0f;
21
22 //Continue to chase
23 while(true)
24 {
25 //Increment time
26 ElapsedTime += Time.deltaTime;
27
28 //Set destination to player
29 ThisAgent.SetDestination( PlayerTransform.position);
30
31 //Wait for next frame
32 yield return null;
33
34 //Has timeout expired?
35 if(ElapsedTime >= ChaseTimeOut)
36 {
37 //If cannot see player, change to idle
38 if(!CanSeePlayer)
39 {
40 //Change to idle
41 StartCoroutine(State_Idle());
42 yield break;
43 }
44 else
45 break; //can see player again
46 }
47 }
48 }
 
Search WWH ::




Custom Search