0
\$\begingroup\$

I'm making a endless runner game, and i have a trigger box following the character, behind the camera. I want it to destroy any kind of object, after the trigger box exits the object. so far i have written this for the code, but it doesn't seem to be correct, and actually doesn't work!

 void OnTriggerExit (Collider other)
 {
     Destroy(other.gameObject);
 }

What should i add to this? Thanks.

\$\endgroup\$
0
1
\$\begingroup\$

In order for OnTriggerExit() to work, at least one of the game objects involved in the collision must have a rigid body component attached.

\$\endgroup\$
0
\$\begingroup\$

Can I make a suggestion? Instead of moving the world, Move the objects via an offset. It will give the illusion that the player is moving through the world, while simplifying the process. To destroy objects you then just test for its position. Say negative X is behind you. Any object that goes beyond some arbitrary distance, say -10.0f will be eligible for destruction. You won't need any fancy collision detection. Remember, KISS: Keep It Simple Stupid.

\$\endgroup\$
2
  • \$\begingroup\$ This seems more like a comment than an answer. \$\endgroup\$ – Gnemlock Nov 9 '16 at 5:18
  • \$\begingroup\$ That's not a bad idea, but in my case, i guess this way is better! Plus I'm mostly through with the hard parts. Thanks anyways. \$\endgroup\$ – MrChips Nov 9 '16 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.