Classes are a crucial component for object orientated programming, or OOP. The premise is that you can create clean, organized programs. It allows you to break functionality into separate classes and have methods for each individual feature. The reason we would use this is because it is easier to debug and maintain.
Let’s take a quick look at an example of how you can create a couple methods of creating the code for something, and why doing it through a more streamlined class method is easier. First, we can create a new public class above our monobehavoiur:

As we can…

Now that our player has a little bit more power behind him, let’s look at giving our enemies a chance at spawning with a shield. For now, we will have it applied to the 1 enemy we have in the game currently, but we will be looking to add new enemy types in the future.
To start, we will need to drag an enemy prefab into our hierarchy under the enemy container then drag a shield onto it. As well, we will change the colour on our shield so that it is slightly different from our player one. …

Now that we have added in a couple new types of powerups, let’s look at how we can balance out the rates of the spawns so that we have a much higher chance to get ammo, and a lower chance for health based powerups. If we kept the current rates, we are looking at a ~16% chance that we will spawn ammo, which can feel like forever in some cases when the player is out of shots.
There are multiple methods that can be used for this process, however in this case, we will use a switch statement within our spawn…

Today we will take a look at adding in a new type of shot for our player. We already have just our basic shot and a triple shot, but now we are going to add in a laser that will expand in it’s width as it travels and will destroy everything in it’s path. This is relatively simple to adjust, as we just have to tag our new laser as “Tsunami” and add a new line of code in the enemy script to account for the interaction with this new laser.
Before we do that however, we need to actually make…

Today, we are going to take a look at how we can create a new powerup to repair the damage dealt to our ship. To start, we need to create a new powerup sprite to work with and attach our rigidbody, box collider, script, animation and audio clip to it, like we have with all of our other powerups. From there, we can go into our player script and add a couple new voids that will tell Unity how we want our repair system to work:

Today we will look into how we can limit the usage of our thrusters so that the player can’t just stay at a boosted speed infinitely. As to how the implementation of the thrusters is done, we did so here.
First, we will need to create an object to have our thrusters work from:

While loops within C# provides us to repeatedly execute a block of code as long as the specified conditions are met. Once the requirements of the code block is false, it will not run the loop.
When making a while loop, more often then not, you will see them within a coroutine. This is because it allows our coroutines process the continuously run until we don’t meet the requirements anymore. However, a key aspect to remember when running the routine is to not get it stuck in an infinite loop:

With a while loop as such, our routine will run…

Today we are going to look at how we can increase the power on our shields and give a visual queue to the player so that they know when it is about to be destroyed. First, we will need to go to our player script and add a shield charge variable to work with:

From here, we can go into our player damage portion of the script and add in a switch statement to cycle through our different charges of the shield:

Today we will be looking at creating an indicator for when our player takes damage aside from the burning thrusters. What we will look at implementing is a camera shake method. First, let’s go to our Player script and create a new variable to attach our camera to:

From here, we will create a new Coroutine within our player script that will enact our camera shake:

Now that we have added a ammo feature, let’s give our player a way to reload their ammo, otherwise this game would be over pretty quick if we can only get 15 shots off. First, let’s get our sprite for the ammo made up:

As with our other sprites, we need to add a rigid body, box collider, animator and our power up script onto it. From there, we can go into our player script and create a line of code for when we collect our new powerup:

Jordan Evans

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