//OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { agent.transform.position = SavedPosition; if (m_enemyNavController.NoiseTarget && m_enemyNavController.currentNoiseType == NoiseController.NoiseType.Run) { enemyAI.EmenyHeardRun?.Invoke(); } else if (m_enemyNavController.VisibleTarget) { m_enemyNavController.OldVisibleTarget = m_enemyNavController.VisibleTarget; timer = 2; if (Time.time - savedTime >= m_enemyNavController.CounterUpdateTime) { m_enemyNavController.Counter += m_enemyNavController.ModCounter(m_enemyNavController.transform, m_enemyNavController.VisibleTarget); savedTime = Time.time; } m_enemyNavController.transform.LookAt(m_enemyNavController.VisibleTarget.transform.position); if (m_enemyNavController.Counter >= m_enemyNavController.Counter_Alert_MaxValue) { enemyAI.AlertStateMaxCounter?.Invoke(); } } else { if (m_enemyNavController.NoiseTarget) { if (m_enemyNavController.currentNoiseType == NoiseController.NoiseType.Walk) { timer = 2; m_enemyNavController.transform.LookAt(m_enemyNavController.NoisePosition); } else if (m_enemyNavController.currentNoiseType == NoiseController.NoiseType.Object) { enemyAI.EmenyAloneHeardObj?.Invoke(); } } else { timer -= Time.deltaTime; if (timer <= 0) { enemyAI.AlertStateMissThePlayer?.Invoke(); } } } CheckHiddenPlayer(); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (m_enemyNavController.VisibleTarget) { if (!PlayerWasInFov) { GameManager.instance.EnemiesInResearch.Add(m_enemyNavController); PlayerWasInFov = true; } m_enemyNavController.OldVisibleTarget = m_enemyNavController.VisibleTarget; if (Time.time - savedTime >= m_enemyNavController.CounterUpdateTime) { m_enemyNavController.Counter += m_enemyNavController.ModCounter(m_enemyNavController.transform, m_enemyNavController.VisibleTarget); savedTime = Time.time; } agent.destination = new Vector3(m_enemyNavController.VisibleTarget.position.x, m_enemyNavController.transform.position.y, m_enemyNavController.VisibleTarget.position.z); if (m_enemyNavController.Counter >= m_enemyNavController.Counter_Research_MaxValue) { enemyAI.ResearchStateMaxCounter?.Invoke(); } } else { CheckHiddenPlayer(); if (m_enemyNavController.NoiseTarget) { agent.SetDestination(new Vector3(m_enemyNavController.NoisePosition.x, m_enemyNavController.transform.position.y, m_enemyNavController.NoisePosition.z)); if (m_enemyNavController.currentNoiseType == NoiseController.NoiseType.Object) { GameManager.instance.EnemiesInResearch.Remove(m_enemyNavController); PlayerWasInFov = false; } } else if (agent.pathStatus == NavMeshPathStatus.PathComplete && agent.remainingDistance < 1f) { enemyAI.ResearchStateMissPlayer?.Invoke(); } } }