private void OnCollisionEnter(Collision _collision) { if (_collision.gameObject.tag == Constants.Tags.Bullet) { m_currentState = FollowPlayerPerception.Hurt; } }
private void OnEnable() { m_currentState = FollowPlayerPerception.ChasePlayer; m_agent = GetComponent <NavMeshAgent>(); if (m_agent == null) { Debug.Log("NavMash Agent Component doesn't exists"); } }
private void Update() { if (m_currentState == FollowPlayerPerception.Hurt) { return; } Collider[] colliders = Physics.OverlapSphere(transform.position, m_sightRadius); if (colliders == null || colliders.Length == 0) { m_currentState = FollowPlayerPerception.LostPlayer; m_agent.destination = transform.position; return; } Collider playerCollider = colliders.Where(x => x.tag == Constants.Tags.Player).FirstOrDefault(); if (playerCollider == null) { m_currentState = FollowPlayerPerception.LostPlayer; m_agent.destination = transform.position; return; } else { if (Vector3.Distance(transform.position, playerCollider.transform.position) <= m_attackRadius) { m_currentState = FollowPlayerPerception.PlayerIsCloseEnough; } else { m_currentState = FollowPlayerPerception.ChasePlayer; } } m_agent.destination = playerCollider.transform.position; }