OnCollisionEnter VS OnTriggerEnter - When To Use Them.
In Unity we primarily deal with two types of collisions. We have hard surface collisions for things like balls bouncing off of walls or car crashes. And we have trigger collisions for instances like gathering a coin when we run over it, or collecting a power up as we move through it.
OnCollisionEnter() is called when a collider/rigid body has begun touching another rigid body/collider. this method passes the Collision class, which contains information about contact points, impact velocity and other attributes.
On the other hand we have trigger collisions, which are called using the OnTriggerEnter() method.
In contrast to OnCollisionEnter(), the OnTriggerEnter() method calls the Collider class, which is a base class of all colliders. For trigger collisions to function properly, both game objects must have a collider component. At least one of the objects must have Collider.isTrigger enabled and contain a rigid body.
If we select our Enemy Prefab, we can see that it has a collider and a rigid body component. Is Trigger box is checked on the Box Collider. This object meets the requirements for the OnTriggerEnter() method.
We can see that the Laser Prefab also contains the required components for the OnTriggerEnter() method.
If we implement this if statement inside our OnTriggerEnter() method, we expect both the enemy and the laser to be destroyed when they collide.