A space shooter would not be much fun without power-ups.
Let’s go over a simple implementation of adding a power-up to our game.

Start by dragging in the sprite for the power-up into the hierarchy:

Rename the object to something suitable and adjust the size. Set the Sorting Layer to Foreground. Add a Box Collider 2D and a Rigidbody 2D. On the collider enable Is Trigger and on the Rigidbody set Gravity Scale to 0:

Open up the Player script and add public function called EnablePowerup and a coroutine called TripleShotCooldown. Start TripleShotCooldown from EnablePowerup. In TripleShotCooldown enable tripleshot and then yield for the specified time before disabling again:

Open the new script Powerup. Set up the movement similar to the Enemy script:

Add the OnTriggerEnter2D function and set it to call the EnablePowerup function on the player:

Create an empty game object and call it something suitable. Drag in three copies of the Laser prefab. Position each prefab so it fits the Player object and then turn the previously empty game object into a prefab:

Now drag the power up to the spawn manager and the new projectile to the player object:

As the projectile objects are added as a children of another object it is important that the clear up code is updated to reflect this:

The whole power-up script:

Good luck!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store