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\$

1 Answer 1

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\$
2
  • \$\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\$ Commented Apr 14, 2017 at 18:00
  • \$\begingroup\$ No worries. We all gotta start somewhere. Good luck in the future! \$\endgroup\$
    – Zebraman
    Commented Apr 14, 2017 at 18:58

You must log in to answer this question.

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