Setting up the break time with an Asteroid!

Matej Marek
3 min readApr 25, 2021

--

A game like this should come with different levels or waves upon waves of enemies. However, we need to create a break for the player so that he may get used to the controls, figure out how to beat his enemies, and so forth. And we will do that by creating a destructible Asteroid, which will act as a form of the ‘Start button.’

And here it is, introducing the Asteroid Prefab - we will be setting it with the ‘Circle Collider 2D’ component, with ‘Is Trigger’ parameter on. As well as with the ‘Rigidbody 2D’ component with ‘Gravity Scale’ set to 0.

Next up, I have set up the Explosion animation, which will be played upon the destruction of the Asteroid:

With all of this done, we need to create a scripted behavior for the Asteroid, and thus the ‘Asteroid’ script is born and attached to the prefab.

In this script, we first define the rotation speed of the asteroid and start slowly rotating him around its axis.

Then we need to define when the Asteroid gets destroyed - and let’s say it can only be destroyed by a laser for now. When it is, we need to instantiate an explosion on its position and destroy all three objects one after the other.

Now, we need to add a reference to the ‘SpawnManager’ and when the Asteroid gets destroyed, call the ‘StartSpawning()’ method in the ‘SpawnManager’ to start spawning enemies, and powerups, and everything else. Basically, to start the level.

Now we need to define the ‘StartSpawning()’ method in the ‘SpawnManager’ script, which is pretty straightforward.

And that is all! - now, whenever the asteroid gets destroyed, the game begins!

One more small thing we will be adding today is the replacement for my placeholder particle effect for the movement and replacing that with a very simple ‘Thruster’ animation for now.

But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!

--

--

Matej Marek
Matej Marek

Written by Matej Marek

Aspiring and eager beginner Unity developer

No responses yet