With our game out of the prototype phase, it’s time to look into giving the Player something to help them out — enter the Powerup!
Let’s start with a temporary improvement to the Player’s weapons —using the sprites in the 2D Space Shooter assets from Filebase, we have the sprites for a Triple Shot powerup so let’s create the new weapon upgrade.
Using the existing Laser prefab, we can create a cool new weapon that fits the name of our powerup nicely and make a new prefab of this.
With the weapon created, we need a way to activate it. Using the aforementioned assets, we can make the visual for our powerup collection —
Give the powerup a collider and a script with functionality to fall down the screen (and a Rigidbody if your Player doesn’t have one) then we’re ready to start coding the new weapon.
The basics of using coroutines are covered in this article.
With our Player set up to activate/deactivate the upgraded weapon, we just need to add some collision code to our powerup script —
After checking it is the Player we have collided with (make sure you place a tag on the Player and ensure the spellings match exactly), we need to communicate with our Player script — I covered the basics of script communication here — and then call our method for activating the Triple Shot powerup. With that we can create the illusion of ‘collecting’ the powerup simply by destroying it.
Save the scripts, head back to Unity and make sure you make the appropriate assignments for the weapon prefab and powerup speed in the inspector and we’re ready for a test —