My GameDevHQ Journey Day 45: Add a Secondary Fire Powerup pt. 1

Nnamdi Azikiwe
5 min readFeb 25, 2023

--

Objective: Create the Neutrino Powerup to fire a Neutrino Bomb

Today we are going to demonstrate how to add a Secondary Fire Powerup in Unity. Its name is Neutrino. It will be arm the Neutrino Bomb replacing the player’s standard laser for five seconds. When the Neutrino Bomb collides with an invader it will spew six Neutrinos as multi-direction shots, It also appears as a rare spawn. To get started, let’s fire up Gimp and create the Neutrino Powerup followed by the Neutrino Bomb and the Neutrinos.

Creating the Neutrino Powerup in Gimp.

The Powerup was created using the same process we covered in creating our Health Powerup and Ammo Powerups, so we wont go over that here. To create our Neutrino Bomb we looked to GameDevHQ’s Filebase which has a set of Missles. We took one (shown below) brought it into a Unity scene, and took a screenshot. Over in Gimp the background was deleted from that image became the Neutrino Bomb.

The Neutrino Bomb.

Collecting the Neutrino Powerup gives the Player five seconds to fire the Neutrino Bomb. When the Bomb collides with an invader, six Neutrinos spew forth. The Neutrinos were also created in Gimp.

Six Neutrino sprites spew when the Neutrino bomb hits an invader.

Now is time to animate the Neutrino Powerup. To begin creating the animation, we first turn the frames of the animation into sprites. We accomplish that by selecting all the frames in the Project tab. Then change the Texture Type in the Inspector tab to Sprite (2D and UI). Clicking the Apply button at the bottom of the Inspector complete the changes.

Turning PNG images into Unity sprites.

Once that is done, all we need do is drag our sprites onto the timeline to create the animation.

Creating the animation on the Animation tab.

That’s all it takes to create the Neutrino Powerup animation.

Our animated Neutrino Powerup.

When the Neutrino Powerup is collected, the Player has five seconds to use the Neutrino Bomb as a projectile. When the Neutrino Bomb hits an invader, it explodes spewing six Neutrinos to collide (hopefully) with any nearby invader. To make all that happen we need to provide the Neutrino Powerup as a collectible.

Neutrinopowerup added to SpawnManager

First, we turned the NeutrinoPowerup into a Prefab. Next, we add the Neutrinopowerup in the array of Powerups in SpawnManager.

Random range increased to 6.

In the SpawnPowerupRoutine we increase the range in the Random.Range to account for the new Powerup. Now we need to make a couple of changes to make use of the NeutrinoPowerup. To enable collection of the NeutrinoPowerup we add a Box Collider 2D and Rigidbody 2D components to the powerup. The Checkbox for Is Trigger should be checked along with reducing the Gravity Scale to 0.

Checking Is Trigger and setting Gravity Scale to 0.

We have the ability to collect the Neutrino Powerup. But, it doesn’t change anything. The laser is still the same. To change that we need to make some modifications to the Player script.

Collecting the Neutrino Powerup changes nothing.

In the Player script we add a private bool variable to enable and disable the Neutrino Bomb functionality.

Next, we create a method and coroutine. The NeutrinoActive method sets _isNeutrinoActive to true and starts the NeutrinoPowerDownRoutine. NeutrinoPowerDownRoutine sets the time to disable the Neutrino Powerup.

The NeutinoActive and PowerDown Routines.

In the FireLaser method of the Player script, we added an else to check our _isNeutrinoActive boolean. When it is true, we instantiate the NeutrinoPrefab, otherwise we use the standard laser.

Whenever the Player collects a Powerup our Switch statement determines the next action based on the powerupID. That means we need to add a case for the Neutrino Powerup.

Our Enemy script needs an adjustment to account for colliding with the NeutrinoBomb. To do that we add a vertical bar in the if statement to check for collision with the Laser. This enables the if to be true when colliding with the NeutrinoBomb.

Lastly, we create a script for the NeutrinoBomb itself that moves it towards the invader.

And with that our NeutrinoBomb Powerup gives us the functionality of a Neutrino Bomb taking out the invader.

The Neutrino Bomb fires, but where are the Neutrinos?

Now we need to add the Neutrinos to eliminate any nearby invaders. We will add that functionality tomorrow, along with making the Neutrino Powerup a rare spawn.

--

--

Nnamdi Azikiwe

Join me on a 90+ day journey in Game Development with Unity 3D using C#.