0
\$\begingroup\$

I am making a Breakout game. I have bricks with box colliders and the ball is a rigidbody2d with circular collider. I have applied the PhysicsMaterial2D on the ball with bounciness set to 1 so the ball is bouncing off the bricks as intended. Now I want to detect this collision in C# so I could destroy the brick but I cannot enable the isTrigger property as it will disable the collisions in that brick. So, I am looking for a way to do that.

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

Rather than using trigger, use OnCollisionEnter2D.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter2D.html

This fires whenever a collision is detected, and should do exactly what you need.

\$\endgroup\$
  • \$\begingroup\$ That worked. Can't believe this was so easy. I should've researched some more. Thanks for the help. This is my first day learning Unity. :) \$\endgroup\$ – Napstablook Apr 14 '17 at 18:00
  • \$\begingroup\$ No worries. We all gotta start somewhere. Good luck in the future! \$\endgroup\$ – Zebraman Apr 14 '17 at 18:58

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.