IEnumerator WaitForWaypoint(Vector3 _dest) { _agent.destination = _dest; Debug.Log("Agent moving to destination " + targetWayPoint); while (!_agent.hasPath) { yield return(null); } while (_agent.realRemainingDistance() > _agent.stoppingDistance && playerFound == false) { // Debug.Log ("Remaining Distance: " + _agent.realRemainingDistance ()); if (_agent.isStopped) { Debug.Log("Agent stopped"); } yield return(null); } // Debug.Log ("Agent Next Phase"); if (_agent.realRemainingDistance() <= _agent.stoppingDistance + 0.5f) { Debug.Log("Agent reached destination"); float waitTimeMod = waitTime; while (waitTimeMod > 0 && playerFound == false) { waitTimeMod -= Time.deltaTime; yield return(null); } if (playerFound == false) { movingEnemy = StartCoroutine(WaitForWaypoint(NextDestination())); } } else { Debug.Log("Agent move interrupted"); } }