Making the PowerUp System Modular

In the last two articles, we created a PowerUp for the Player to shoot 3 Lasers instead of 1 and set it up to spawn with the Spawn Manager. In this article, we will make the PowerUp script modular instead of making each PowerUp a separate script that does the same thing and add two more PowerUps.

Modular PowerUp System

Before we make the new PowerUps, we will set up the PowerUp script to be modular to add to those new PowerUps right away for testing their functionality.

PowerUp ID with Pseudo-code
Modular PowerUp script
PowerUp Prefab Array
Adding the Array to Instantiate

Speed Boost PowerUp

Create the Sprite gameobject, animate it, add Collider and Rigidbody, add the PowerUp script, change Power Up ID to 1 and make it a prefab like the Triple Shot PowerUp.

Creating the Speed Boost PowerUp Prefab
Variables for Speed Boost
Adding Speed Multiplier to Movement Code
Method and Coroutine for Speed Boost
Activating Speed Boost
Hooking Up the PowerUps
Speed Boost Spawning (eventually) and Working

Shield PowerUp

Create the Sprite gameobject, animate it, add Collider and Rigidbody, add the PowerUp script, change Power Up ID to 2 and make it a prefab like the other PowerUps.

Creating the Shield PowerUp Prefab
Shield Variables
Turn Off Shield Visual at Start
Turning Shield On
Blocking Damage and Turning Off Shield
Activating Shield
Creating Shield Visual
Hooking Up Shield PowerUp Prefab

Quick Clean Up

Now for a quick clean-up of the code.

Fast Way to Rename a Variable in VS
Tooltip for Power Up ID
Organizing Folders

Unity Developer, Software Engineer, Game Designer

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