private void OnTriggerStay(Collider other) { if (ActiveState != SkeletonState.DIED) { if (other.gameObject.name == "Player") // we can add inside this: && other.gameobject.GetComponent<PlayerCombat> != null { if (FaceAndCheckObjective(other.transform.position, detectionAngle) && ActiveState != SkeletonState.ATTACK) //in vision { if (Vector3.Distance(other.transform.position, transform.position) < nextAtack[1]) { ActiveState = SkeletonState.ATTACK; } else { if (ActiveState != SkeletonState.CHASE) { ActiveState = SkeletonState.CHASE; chase.PlayerFound(); } target = other.transform.position; } } else //out of vision { if (ActiveState == SkeletonState.CHASE) { ActiveState = SkeletonState.PLAYER_LOST; chase.PlayerLost(target); nav.SetDestination(target); } if (ActiveState == SkeletonState.ATTACK) { target = other.transform.position; } } } } }