Galaxy Shooter 2D — Triple Shot #6
It’s time to make my game feel like a real game, not just some space-themed target practice. A good way to start is by developing one of the most common features for a space game: powerups, which allow the player’s ship to use special abilities! And so, I set forward to make the very first powerup: Triple Shot!
Three cannons for three lasers
The powerup name is self-explanatory: I want to spawn three lasers instead of one when the ship collects the respective powerup. The spawn points could either be specified through code… or I could just make an empty GameObject, assign it three lasers, make it a prefab, and Instantiate that instead of the default laser. And that’s what I did (I probably will change that in the future. I will explain why later).
The powerup needs a body
Obviously, we need a vessel the player can pick up. Adding a sprite and a trigger collider should suffice for me to start coding the functionality.
It’s not going to code itself
Before we give create the powerup script, let’s define the behavior. Declaring two variables, one for the Prefab and the other to check if the Triple Shot powerup is active, and, with just that, I can simply replace the prefab to Instantiate in only one line of code!
I then created one coroutine for the duration of that powerup, and two methods to start and stop it. Using a lambda operator, whenever this script uses the boolean, it will update to whatever I specify it to check. In my case, whenever the coroutine is active.
The ship triple shot ability is now working. Now we need the powerup to trigger it when it makes contact with the ship.
In the next article, I will show you how I animated the Triple Shot sprite!