5
\$\begingroup\$

I've 2 object: a Player and a Bonus object.

In both script I've "OnTriggerEnter" script.

In Player OnTrigger I: Take Bonus value and add it to my Player (health, point, ammo)

In Bonus OnTrigger I: Play audio (when take it), Play Particle System and so on...

But, it seems it's called only Player's OnTriggerEnter ... Why ?

In Unity, if I have OnCollision/OnTrigger enter in both object, which event is called ? Both ?

Thanks

\$\endgroup\$
4
  • \$\begingroup\$ please post the settings of each collider and rigidbody for your test \$\endgroup\$
    – Stephan
    Dec 11, 2017 at 21:24
  • 2
    \$\begingroup\$ Please check if both colliders have "IS TRIGGER" flag checked. \$\endgroup\$
    – LebRon
    Dec 12, 2017 at 8:18
  • \$\begingroup\$ Is there a rigidbody, is it the only rigidbody in that hierarchy? \$\endgroup\$
    – Nikaas
    Dec 12, 2017 at 8:55
  • \$\begingroup\$ Its been a long time but as far as I remember OnCollisionEnter or OnTriggerEnter will be executed when Rigidbody is attached to that object. \$\endgroup\$ Dec 12, 2017 at 19:23

1 Answer 1

2
\$\begingroup\$

In order to fire onTrigger, you need to have colliders in both game objects with at least one of them with a rigidbody and with at least one of them with isTrigger set to true.

When that's the case, the OnTriggerEnter is called on all game objects involved if you have the OnTriggerEnter() function written in the scripts attached to them.

It doesn't matter which one has the rigidbody, or which one has isTrigger set to true. You can mix and match the settings in any way you want.

You can also have both object with isTrigger set to true. If you are having issues, you may have misspelled the function call on the bonus object.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .