Power Up System in Unity — Part 2

Understanding the logic of PowerUp

Ok! This time, let’s go over how we can spawn TripleShotPowerUp similar to how the enemies are being spawned + I will show you a simple animation that will add quality to the game!

Spawning TripleShotPowerUp

To spawn TripleShotPowerUp, let’s first open up SpawnManager script. It’s going to be really really similar to how we did for Enemy by using StartCoroutine() with IEnumerator.

  1. At the top of the script, let’s create a variable for PowerUp prefab that we can use.
  2. Under void Start(), we will create StartCoroutine(SpawnPowerUpRoutine());
  3. Then, we will create a new method with IEnumerator that receives SpawnPowerUpRoutine() from Coroutine.
  4. Use while loop that will activate while ‘bool _stopSpawning’ is false (it will turn to ‘true’ when the player is dead). Under while loop, follow the steps below.
  • create a variable that will get a random X position value between -5 to 5 (left and right ends of the game screen). Then, use it to instantiate the PowerUp prefab.
  • create another variable that will get random seconds between 5–10, then use it to WaitForSeconds(). This will spawn the PowerUp prefab at random timing and not too consistent.

Power Up → ‘_isTripleShotActive’ to TRUE

Ok, in the previous article, in PowerUp script’s OnTriggerEnter2D(), I realized that I did not make it clear how we are calling the player script and changing ‘bool _isTripleShotActive’ to TRUE (so that we can shoot Tripleshot).

Here are what I did:

  1. In Player script, create a new method called ‘TripleShotEnabled()’ that will turn ‘bool _isTripleShotActive’ to TRUE.
  2. In PowerUp script, when collided with the player, get player script by ‘GetComponent<>’. Then, if found, call this ‘TripleShotEnabled()’ method.
In PowerUp Script (LEFT) + In Player Script (Right)


Now, we need to limit the time so that the player can shoot tripleshot for few seconds only, then return to a single laser shot.

  • In Player script, we previously implemented FireLaser() method so that we can activate either tripleshot or singleshot. We just need to add Coroutine that will count 5 secs, then disable Tripleshot.

Bonus — Animated PowerUp Prefab!

Let’s add some spice to TripleShot PowerUp. The current one looks a bit plain, but what if we add an effect of flashing colors? Here what we need to do.

  1. Prepare a series of sprites with different colors — This can be done in photoshop, illustrator, etc. Luckily, I have these sprites ready to be used!

2. Select TripleShotPowerUp Prefab, then go to Window → Animation → Animation. This will open an animation window. Click on ‘Create’ when the window pop up.

3. It will take you to a folder to save this animation file. Create a new folder called, ‘Animation’. Then, save it as ‘TripleShotPowerUp_anim’.

4. Click on the record button at the top left (red circle). The red bar will show up on the timeline to indicate that we are in record mode. Select all of the sprites that we want to animate with. Then, drag and drop into the timeline window. Press the record button again to stop the recording mode.

That’s it! Now, we have the animation set up. Simple and Easy, right?

You can see the big difference between before and after animation!

The game is looking better and better! Awesome!

Thank you so much for reading!




XR Unity Developer / Designer / Architect

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Clean Coding Principles

Use These 7 Software Development Tips For Successful Teams

Unlocking Web Audio — the smarter way

How to start with Placements Interview Preparation and my Interview Experience with American…

How my App won third place in an International Student Competition

Building a Beautiful Disney MVVM Android Application (2): Jetpack + Architectures

Writing a program using Java

Simple TDD in Laravel with 11 steps

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

More from Medium

Adding a burst laser powerup

Journal 137 — Unity App Development, AR Demo Add UI

2.5D Platformer — Improving the Ledge Grab #10

Creating An fbx Emission Layer For Unity Using Photoshop & Blender