Questions about collision detection for basic enemy AI

I have a problem which I’ve already solved… but I don’t think it’s the Unity way or the “correct” way to do things.

Problem: I have a 3D enemy standing on a mesh. If I get within a certain radius the enemy should chase me. If I get a certain distance away he should idle, and if I get too close he should attack.

My method: I used 3 floats to represent the 3 radius distances, and on every update() call I check these distances and adjust the animations as needed.

The problem - I’m running through too much logic on every Update() (in my opinion) - why not just change animation states when the radius is reached. My first thought is a Sphere collider so I can use OnCollisionEnter and OnCollisionExit. But how do you use more than 1 collider on 1 object? How would I be able to tell which is being hit in code? Is this even the right approach or is the Update() method the way to go?

One last note - I’d like the enemy to attack only if he can “see” the player. I think creating a cone shape of some type projecting from the enemies face and checking collisions with this would be the solution. Am I on the right track? Is there such thing as a cone collider? I doubt it but if anyone has suggestions to my issues I’m glad to hear them.

If you want to use an extra sphere collider to detect if player is in attack range, you can just make a new empty gameObject and attach it to the enemy as child object.
Then attach your trigger collider to that new child object.
You can write your OnTriggerEnter stuff on that child object.

This should be your hierarchy:
Enemy
-your collider, scripts n stuff, rigidbody
newGameObject
-Collider(trigger collider)
-script that handles collisions

For the enemy detecting the player you will have two vector3 values:
One is “Vector3.Normalize(enemy.transform.forward)” (the way enemy is looking)
Other one is “Vector3.Normalize(player.transform.position - enemy.transform.position)” (direction of the player to enemy)

If these two vectors are close to eachother it means player is more to the center of enemys look direction
If not enemy is probably looking at some other direction
You can just subtract two vectors and get magnitude of it, to find how close they are (this is where you set the field of view for enemy)

This should do exactly that cone collider effect that you are talking about:)

You can just use Physics.raycast to make sure the enemy is not seeing trough walls
(raycast basicly is casting a ray from a position to some direction and getting the first object that it hits. Its pretty simple you can look it up)

I hope this can help