void OnTriggerExit(Collider col) { // Check if it was the player if (col.attachedRigidbody && col.attachedRigidbody.gameObject.name.Equals("Player")) { // Check the state if (stateMachine.GetStateName().Equals("Attack")) { playerInRange = false; // Change to chase state State_Chase state = new State_Chase(this); state.SetAnimator(anim); state.SetSpeed(moveSpeed); state.SetNavAgent(navAgent); state.SetChaseTarget(col.attachedRigidbody.gameObject); stateMachine.SetState(state); attackCollider.radius = attackRange; } } }
void OnTriggerEnter(Collider col) { // Check if player is in vision range if (col.attachedRigidbody && col.attachedRigidbody.gameObject.name.Equals("Player")) { // Determine which state we should change to if (stateMachine.GetStateName().Equals("Patrol") || stateMachine.GetStateName().Equals("Return")) { visionRange.enabled = false; attackCollider.enabled = true; // Change to chase state State_Chase state = new State_Chase(this); state.SetAnimator(anim); state.SetSpeed(moveSpeed); state.SetNavAgent(navAgent); state.SetChaseTarget(col.attachedRigidbody.gameObject); stateMachine.SetState(state); attackCollider.radius = attackRange; return; } else if (stateMachine.GetStateName().Equals("Chase")) { playerInRange = true; // Change to attack state State_Attack state = new State_Attack(this); state.SetAnimator(anim); state.SetTarget(col.attachedRigidbody.gameObject); state.SetAttackDelay(attackDelay); state.SetAttackCooldown(attackCooldown); state.SetProjectile(projectile, attackDamage, 0, attackRange); stateMachine.SetState(state); // Keep the attack more persistent attackCollider.radius = attackRange * 1.25f; } } }