Creating Modular PowerUp in Unity!

Creating a variable

Currently, let’s say I want to have a total of 3 types of PowerUp.

  1. TripleShot / 2. SpeedUp / 3. Shield
  • TripleShot = 0 / Speed = 1 / Shield = 2

In Player Script

We need to create variables for each PowerUps.

  • TripleShot: Use ‘bool’ to activate or deactivate (we created this previously)
  • Speed: Use ‘float’ or ‘int’ to increase or decrease number (we created this previously as well)
  • Shield: Use ‘bool’ to activate or deactivate.
Variables for each PowerUp
  • TripleShot: we went over this in the previous article.
  • Speed: we can set it to 10 when activated and return to 5.5 when deactivated.
  • Shield: create a bool statement similar to TripleShot (We will go over how to instantiate this in the next article. Stay tuned!)
Coroutine for each PowerUp

In PowerUp Script

Under OnTriggerEnter2D, to distinguish which PowerUp we want to activate, we can use the if statement that will check what PowerUpID number we are looking for, then proceed to call in each method that we created above.



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
Du Young Yoon

Du Young Yoon

XR Unity Developer / Designer / Architect