Get reference to component when you have more than 1

Hi
Currently using 2 BoxColliders on a GameObject. One has a Trigger enabled.
How can I get a reference to either BoxCollider when both are on the same GameObject?

Either make a reference and drag n drop it
Or you can do GetComponents();
then just check if 1 is a trigger (either by an index into the returned array or looping over it).? :slight_smile:

If you have multiple colliders that do different things, its often useful to put these on children GameObjects. Children will still fire off the appropriate events in the parent rigidbody, but then you can check the name of the collider to see which collider fired.

1 Like

^ … or the tag, or the layer. Compound colliders are delicious when abused properly.

1 Like