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.
1 Answer
\$\begingroup\$
\$\endgroup\$
2
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.
-
\$\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\$– ZebramanCommented Apr 14, 2017 at 18:58