Journal 34 — Unity Modifications to Game, Part 2
This article is about the next round of updates to enhance the gameplay.
I’ll cover these modifications:
— Add a collectible that gives back health
— Add a secondary fire power up (special power up)
— Add a scale bar to show the use of the thrusters with a cool down notice if used too long
— Add a camera shake effect if the player takes damage
Health Collectible
For this modification, you can use one of the images from the UI and modify it to move down the screen like other power up game objects.

The health power up is added to the Powerup C# script in the expanded switch statement. Also be sure to add the health game object to the SpawnManager powerup function and drag the prefab into the Inspector.

In the Player C# script, if the health power up is picked up, we can add back a life to the tracker, update the UI display for ship lives, and also turn off the damaged ship thrusters.

Secondary Fire Power Up
In this modification, we can add a secondary fire powerup that spawns a little more rare than other power ups. As you see from the animation below, this power up unleashes a spiral of lasers for a few seconds to try and clear all enemies.

To make this spawn slightly more rare than other power ups, you can add a check for random numbers from say 0 through 19, and if the results fall below 15, then call a random power up that does not include the special power up. However if the random number is greater than 15, then that calls the special power up.

Update the Powerup C# script with an expanded switch statement.

In the Player C# script the laser shot special power up, we can make a loop to create an array of 50 laser prefabs on the player, they are instantiated at the player’s position, and each laser prefab is given a 30 degree rotation around the z-axis times the position of each prefab in the array. This creates the spiral around effect. Since this is done in a coroutine, we pause for about 0.15 seconds per laser projectile.

Ship Thrusters Display and Cooldown
In this modification, we want to turn on and off the ship’s thrusters when holding in the Left Shift button for maximum amount of time, and then the thrusters have a cooldown period and can’t be used.

The UI update to show the thruster usage is based on a radial bar. You can make a basic circle in any art program, and copy it into the Unity project folder and change to a sprite. See the settings below.

In the UIManager C# script, we add the following variables:

In the Player C# script, we add one more condition to when using the thrusters, plus we show visually the thrusters when they can be used.

In the Player C# script, we add two public methods that contain a bool variable that will be accessed in the UIManager script.

The last edits for the radial bar is in the UIManager C# script. As described below, we have a timer for how long the thrusters have been activated in comparison to the maximum allowed timer. If the thrusters are used too long, we reference the bool variable in the Player script to disable the thrusters, and show the cooldown text.


2D Camera Shake
The last modification for this article adds a camera shake effect if the player is damaged.

We can create a new C# script and add it to the camera. The script will track the camera’s position and make a random movement of the camera’s position based on a set duration of shaking.

The TriggerShake() method is made public, so we can access this from the Player script when damage is taken.



Thank you for your time!