On trigger enter()
In previous section, important components were added in the colliding objects (asteroids and laser beam). In this section, I will be creating a script called "DestroyOnCollision.cs" script and attach it to Asteroid prefabs. Also, I am going to introduce a new variable "health = 100" to asteroids. Every time the asteroids that are instantiated in the screen are collided by laser, it's health will decrease by 25. And, when the health of the asteroid reaches 0, it gets destroyed. On the other hand, the laser will get destroyed once it collides with the asteroid.
So, when a player instantiate laser beam and it collides with asteroid, OnTriggerEnter(Collider other) method is called. Asteroid should recognize that the object that it just collided with is a Laser Bullet. For that reason, we have already tagged the GameObjects.
Couple of things to remember while scripting this:
Condition 1: Asteroid should collide with "Laser"
If condition 1 is true -->
health of the asteroid should decrease by 25 points, and
other gameObject, i.e., Laser should be destroyed
Condition 2: Is health = 0?
If health reaches 0 --> asteroid should be destroyed
... PROGRESS SO FAR ...