One object with multiple colliders -- how to filter out which one triggers OnTriggerStay?,Excluding a collider from triggering OnTriggerStay, or something similar?

I was loosely following an older tutorial on the official Unity Youtube channel about a stealth game. That one set up enemies and their sight radius by giving them a very large spherical collider. As soon as the player enters it, line of sight checks and so on are performed. The sphere collider is of course marked as a trigger.

However, in my game I also want enemies to be able to open doors. The doors also have colliders on them, and open when someone steps into the collider. The problem is that the huge spherical collider on the enemy also triggers the door opening script. The door should open, but only if the smaller capsule collider, also on the enemy, enters the doors trigger collider. I haven’t found a way to filter out which one I want to trigger the OnTriggerStay method on my door script… is there a way?

One way would be to put the colliders in different layers so that the OnCollision/Trigger function(s) only get called with the right combination(s) of layers.

Another would be to have some code in the OnCollision/Trigger functions that checked what had been collided with, for example looking for some other component (eg Door.cs) or (less good) looking for a particular name, before deciding whether or not to do anything.

I have 1 idea:

1: You can create another Gameobject in the main object of the enemy and call it “Middle” and add the Collider to it.

Then you can do
if(collision.gameObject.name ==“Middle”)


I hope I helped you.