Learn to code by making 2 D space shooter game.
Objective: Control Spawn Wave through the asteroid.
The first step lets drag the asteroid to the hierarchy add a Rigidbody, collider asteroid script attach it.
Asteroid need to rotate through the z-axis, we do this by using transform.Rotate method.
we need an asteroid to get hit by the laser, we use OnTriggerEnter2D to detect collision.
Now we need to set explosion animation, take the first frame drag it to the hierarchy and rename it as an explosion.
Select that object to create animation for it then drag the object to Project folded to make it prefab.
here is article for making animation https://suleimanabdullah.medium.com/learn-to-code-by-making-2-5-d-space-shooter-game-6e97483ad297
Note: Remember to uncheck the animation loop for this animation.
After making it prefabs it's time to instantiate it when the player fires a laser at Asteroid and destroys ourselves. First, we need a game object reference for the explosionprefab then Instantiate then destroy the asteroid.
Next, we want to spawn an enemy when the asteroid is destroyed by a laser go to spawn manager create a public method called StartSpawning then start enemy and power coroutine there.
The last step call this method when the asteroid is destroyed call it inside an asteroid when the laser hits an asteroid.
We need to communicate with the spawn manager first checkout script communication article here;https://suleimanabdullah.medium.com/learn-to-code-by-making-2-5-d-space-shooter-cb1c4c67213b
This is how we start spawning through asteroid, see you in the next article.