Hi, all!
I have a simple OnTriggerEnter function in a script attached to my player, and my player has a box collider that isTrigger.
This is the player’s hitbox.
It seemed to me that every enemy shot was hitting the player, and then I noticed that one of the children objects on the player had a massive Sphere Trigger Collider.
The script was using it, because when I turned it off, shots that didn’t enter the box didn’t register.
How do I get the script to reference / test ONLY the trigger attached to the parent object?
Thanks! - YA
-
Create a tag for your enemies, like “Enemy” or something. Same thing for your player - “Player”.
-
Set your enemies to have the “Enemy”. Set your player with the “Player”
-
function OnTriggerEnter(other : Collider)
{
if (gameObject.tag != "Player" || other.gameObject.tag != "Enemy")
return;
// do stuff
}
-
???
-
Profit!!!
Honestly, though, this is the only way I know how to accomplish what you want.
-
Create a tag for your enemies, like “Enemy” or something.
-
Set your enemies to have those tags.
-
function OnTriggerEnter(other : Collider)
{
if (other.gameObject.tag != "Enemy")
return;
// do stuff
}
-
???
-
Profit!!!