This post will add an asteroid and use it as a trigger to start the game. The player can have some breathing room before receiving attacks from the enemies; in other words, the asteroid’s destruction will trigger the SpawnManager to spawn enemies and powerups.
There are two main steps:
- Build the Asteroid prefab
- — Create the asteroid object with a rigid body, collider, and sprite child component like all the other objects in the game to ensure the physics of colliding work normally
- — Scripting the behavior of the asteroid
- — — Rotate around the z-axis at a certain speed on top of the screen
- — — Explode when hit by the laser
- Script communication between Asteroid script and SpawnManager script
The relatively new thinking involved in the above process is the explosion of the asteroid. Since we don’t have a dedicated explosion but a generic one, we can create a generic explosion effect prefab and let it instantiate at the asteroid position before it gets hit. This explosion effect will play and destroys itself after a few seconds.