Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (stopped)
     {
         animator.Play("idle");
         return;
     }
     if (!isPursuing)
     {
         if (!playerTracker.PlayerDetected)
         {
             // Patrolling
             State = EnemyState.State.Patrol;
             if (Mathf.Abs(Vector3.Distance(this.transform.position, route.GetCurrentRoutePoint())) > 1f)
             {
                 agent.destination = route.GetCurrentRoutePoint();
                 animator.Play("run");
                 // Debug.Log("didnt reach point");
             }
             else
             {
                 route.NextRoutePoint();
                 //Debug.Log("reach point");
             }
         }
         else
         {
             // Begin pursuit
             isPursuing = true;
         }
     }
     else   // Pursuit!
     {
         if (playerTracker.PlayerDetected)
         {
             if (currentBehaviour != null)
             {
                 // Continue Pursuit case
                 StopCoroutine(currentBehaviour);
                 currentBehaviour = null;
             }
             State             = EnemyState.State.Pursuit;
             agent.destination = playerTracker.GetPlayerPosition();
             animator.Play("charge");
         }
         else
         {
             if (currentBehaviour == null)
             {
                 // Begin close search
                 agent.destination = this.transform.position;
                 State             = EnemyState.State.CloseSearch;
                 currentBehaviour  = StartCoroutine(CloseSearchPlayerBehaviour());
                 animator.Play("idle");
             }
         }
     }
 }