Sign in

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles

Our Player can become invincible when they pick up a Shield Powerup, but it only lasts one hit. We’re about to increase the difficulty of our Game, so I think it’s fair that we give them a little more leeway in terms of shield health.

In this article, we’ll give our Player Shield some health, and have that reflect visually by changing the colour and alpha!

The red is a little hard to see on this compressed GIF. But it’s there!

Creating the Shield Health

To have health, first we must create health. Or at least a variable for it!

Inside our Player script, we’ll create an int for the shieldHealth, and also create a reference for the SpriteRenderer…

Our Player can already grab a Speed Boost that allows them to go super fast for the duration of the Powerup, but how about we give them a slight boost when holding the Shift key to escape dire situations?

In this article we’ll implement Player Thrusters when holding the Shift key, but give them a limit to how long they can use it. We’ll utilize UI fill amounts and let it regenerate over time!

Thruster usage and regeneration

Creating the Thruster Logic

Since this Thruster enhancement will be affecting the Player, we’ll creating the logic inside the Player script.

First we’ll create a bunch of variables relating to…

So far our game consists of our Player dodging our Enemies as they fall to the bottom of the screen, while hopefully being able to shoot and destroy them to add to their score.

But now lets add some difficulty to our game and let our Enemy ships fight back!

The [Enemy] strikes back!

Creating the Enemy Laser

The first thing we’ll do is create a Laser for the Enemy that has a different appearance from our Player’s Laser.

We’ll do this by creating an Empty Object and using our Laser Prefab, scaling, duplicating it, then fitting it to our Enemy:

You may think that exiting games would be a function that comes standard in any game you build, however, this is not the case!

If you have a full screen version of your game and you don’t add an exit functionality, the Player could be trapped in full screen and would have to CTRL+ALT+DELETE to close your game! Very unprofessional.

So this short article is on how to prevent that.

One code to rule them all

Since this new code is handling our Game management, it seems best to fit it in the GameManager script!

In our Update() function, we’ll add the one line of code…

As an Audio Engineer, anything that involves sound intrigues me. So learning Unity’s built-in audio system was a pleasure. I am aware of other Middleware such as FMod or Wwise, but for this small project, Unity’s Built-In system will work just fine!

It’s also kind of funny to write this Medium article with just text and GIFS, because you won’t be able to hear any implementation, but trust me, the sounds are being played!

Like this background music, for example, haha.

Creating and Audio Manager

Most games will have an Audio Manager to… mange… the audio. That is, it will handle background music or ambience that fills the whole game. …

To finish up our little section of VFX improvement, I can’t overstate the importance of adding Post-Processing to your game. It has the ability to give you game that extra flair you’ve been looking for.

While it can get complex, keeping it simple and using only a few parameters can do wonders for the aesthetic of your game!

Here is a little A/B comparison:

Installing the Post-Processing Package (Unity 2019.3.14f1)

Depending on which version of Unity you are using, it may or may not already come pre-installed. For Unity 2019.3.14f1, we have to install Post Processing via the Package Manager, and this is how:

First open…

Last article we created a new Explosion to go with our destruction of an Asteroid that would start our Game.

In this section we’ll spruce up our Player a bit — giving them a Thruster, and also implementing some visual cues on the Player to check their Health amount!

That’s a good looking Player Ship! (Until it gets damaged… but still beautiful)

Player Thrusters

In creating the Player’s Thrusters, it will be a permanent Child of the Player object. This ensures it follows the Player.

So, we’ll create the Thruster Game Object and attach it to the Player:

Last article we made our Asteroid Game Object, created a new Explosion VFX and created the basic logic for interaction. This left some bugs, but they are easily fixable.

By the end of this article, destroying the Asteroid will now officially Start our Game and start spawning Enemies!

End Product

Squashing some Bugs

We left off here in the last article:

While we’re still on the topic of Explosions from the last couple articles, let’s implement one more! This time we’ll create an Asteroid that the Player will have to destroy to Start our Enemy Spawning!

Yes, we have a Main Menu now to start our Game, but we’ll be nice and give our Player a little more breathing room once the Game has been initiated.

Let the Game begin!

Creating the Asteroid

If we’re going to destroy an Asteroid, first we must create an Asteroid:

I have a static Image that I’ll use for the Sprite Renderer. Then change our Sorting Layer, and add a Circle Collider…

In the last article we created the Enemy Explosion VFX and fixed up the Animator Controller.

In this article we’ll finish up the process by triggering the animation state through code when the Enemy is destroyed!

Full Functionality (almost). Spot the bug if you can!

Enemy code

The first thing we’ll do is create a reference to our Animator, and then Initialize it in the Start() function:

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