Chapter 16: Creating Modular Powerup Systems

Joshua Kidd
2 min readOct 31, 2023

--

Steps to create the Triple Shot power up in Unity:

  1. Drag the laser from the prefab folder into the Hierarchy so it appears the scene.
  2. Duplicate it twice.
  3. Position the new lasers on the wings.
  4. Make sure the Y values are the same (-0.3) and the X values are opposites (-0.79 and 0.79) so they instantiate at the same position for each wing.
  5. Create an empty GameObject and call it Triple_Shot.
  6. Drag three lasers into the Triple_Shot object.
  7. Drag the Triple_Shot object into my Prefab folder.
  8. Delete the Laser in the Hierarchy to remove from scene.

A Modular Powerup System is more efficient way to add more power-ups to a game than creating a brand-new script for each power-up. Creating a modular system requires a switch statement. Switch statements can be cleaner and more readable than using a long series of if-else statements.

  1. Find the Triple Shot and Speed Boost sprite in the Project folder and move it up into the Hierarchy and name them Triple_Shot_Powerup and Speed_Powerup.
  2. Move the power-ups to the foreground in the sprite renderer and add all the need components. (Rigidbody 2D, Circle Collider 2D, or Box Collider 2D)
  3. Move them into position at the top of the screen and resize to 0.5.
  4. Making sure IsTrigger is checked in their Box Colliders and the rigidbody’s gravity set to 0.
  5. Create a Power-up Prefab folder and drag the two powerups into the folder in the Project window.

Now that the power-ups are created in unity write the modular systems for the powerups using a switch statements. Then code using a coroutine in the player script.

Power-up Script
Player Script
Player Script

--

--