How to check only one Trigger

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

  1. Create a tag for your enemies, like “Enemy” or something. Same thing for your player - “Player”.

  2. 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
}
  1. ???

  2. Profit!!!

    Honestly, though, this is the only way I know how to accomplish what you want.

  1. Create a tag for your enemies, like “Enemy” or something.

  2. Set your enemies to have those tags.

function OnTriggerEnter(other : Collider)
{
    if (other.gameObject.tag != "Enemy")
        return;

    // do stuff
}
  1. ???

  2. Profit!!!