/// <summary> /// Sets the target.. /// </summary> void Update() { if (_characterStatus.IsInvulnerable) { return; } #region Found Player if (_targetSelector.CurrentTarget != null) { Vector3 targetPos = _targetSelector.CurrentTarget.transform.position; Vector3 entityPos = transform.position; Vector3 difference = (targetPos - entityPos); float distance = difference.sqrMagnitude; if (distance > ShootingDistance) { _agent.destination = _targetSelector.CurrentTarget.transform.position; _running = false; } else if (distance < PanicDistance || _running) { _agent.destination = entityPos - difference; _running = true; } else if (!_running) { // Lookat and shoot. _agent.destination = entityPos; transform.LookAt(targetPos); if (!_cooldown) { Fire(); StartCoroutine(Cooldown()); } } } else { #region Follow Path if (_currentCheckpoint == null) { _currentCheckpoint = WaypointManager.GetCheckpoint(_currentOrder); } if (_currentCheckpoint != null) { _agent.destination = _currentCheckpoint.Position; if ((_currentCheckpoint.Position - transform.position).magnitude < 0.1) { _currentOrder++; _currentCheckpoint = null; } } else { // If Checkpoint was null, it doesn't exist. _currentOrder = 0; } #endregion Follow Path } #endregion Found Player #region Animation if (Animator != null) { Animator.SetFloat("Speed", _agent.speed); } #endregion Animation }