How to tell which trigger is detecting with OnTriggerEnter?
I have 2 triggers on my enemies: one handles their vision and the other handles if they reach the player and their hitbox. The enemy script checks if they have overlapped with things and what to do with each thing. I am having an issue where their sight cone trigger activates like it is their hitbox trigger. It is causing a lot of issues and I can't figure out how to tell the triggers apart. You can do it in unreal (which i'm much more familiar with) so I feel there is some way to do it in unity that i'm not aware of.
Answer by lgarczyn · Nov 21, 2019 at 04:15 AM
If both trigger colliders are on different objects, the event can only be detected by the scripts on their respective objects except if a rigidbody is one of the parents, in which case it will get the event too.
You appear to have on trigger collider on the rigidbody, and one on the head. Simply move the one on the rigidbody to its own object, with all associated scripts.
If you really want to "tell them apart", you'll have to move the logic to the player, using its own OnTriggerEnter, which is a terrible idea.
Your answer
Follow this Question
Related Questions
Unity 5.2.0f3 Triggers Broken?? 1 Answer
OnTrigerEnter not working 2 Answers
AI Raycasting 0 Answers
Checking when two triggers intersect 1 Answer
Calling "OnTriggerEnter" when a parent object has a rigidbody 0 Answers