Once you’ve created a version of your application in Unity you want to be able to test or share without having to have Unity open, it’s time to build the application to an executable file.

Doing so is simple, clicking file →build settings will open the build window where you can choose which scenes to include in the build, useful if you have been using a test scene for building new features or have unfinished levels that you don’t wish to include. …

To play an audio clip in Unity, you only need to add an “Audio Source“ component to a game object, enable “Play On Awake”, and drag the desired audio clip into the AudioClip field.

To play an audio clip through code, in a response to something happening in the app is not much more complicated.

First you need a reference to an audio source.
Here I placed my audio source on a separate game object and dragged it into the open field in the inspector.

To start working with post processing in Unity is simple, go into the package manager (window — package manager), choose Unity packages in the packages dropdown menu, and hit install.

Once the package has been installed, return to your hierarchy and create a new empty game object, and add the “Post-process Volume” component.

Before we can see any post processing effects however, we need to add a “Post-process Layer” component to the camera.

Next we need to create a post-processing layer in the Layer settings, accessed through the layer dropdown menu at the top of the inspector, click add layer…

Usually when making a video game that needs to visualize player health, a health bar or lives counter is the simple and generally reliable way to do it, but it’s also not very interesting to look at.

So lets create some visualization for the player model being damaged.

Here is my healthy player character.

GamedevHQ provided me with some 2D animations to represent player health, a fire with a smoke trail.

Any good game needs explosions.
But how does one make an explosion in Unity?

With animations of course!

GamedevHQ provides a custom explosion animation for the enemy character in their 2D game course.
Just like in my article about 2D animations in Unity, I select the enemy prefab, open the animation window, create the animation, and drag in the animation frames.

However when I try to play the game, the enemies explode immediately.

Once you’ve created some basic gameplay for your game, you’ll probably have to be able to either restart because you lost, or go to the next level.
This is where the LoadScene function comes in.

Taking either and int, for the sceneBuildIndex, which you can see in the build settings window on the right.

As part of the GamedevHQ 2D game course I was tasked with creating a retro game over screen. So, a great big text box saying “GAME OVER”, but to add some spice, make it flicker on and off.

First I need the great big GAME OVER text, a simple UI text element handles this nicely.

Building UI in Unity is amazingly powerful and easy.

Start by right clicking in the hierachy, go to UI, and select Canvas

In the Canvas game object you’ll find:
A Rect transform, a sub type of transform that all UI elements use.
A Canvas defining how the canvas is integrated into the application.
A Canvas Scaler, defining how the UI should react to changing screen sizes.
And a Graphics Raycaster allowing you to register clicks on the canvas.

When writing a program, if statements are a powerful tool for branching code, but sometimes you need to make a lot of individual checks on a single variable, and filling up 100+ lines of code with “if else” statements is at best unappealing.

This is where switch statements come in. Taking a single variable and comparing it against a case, here typeOfPowerUp is an integer value with an intended range of 0–2. When the variable and case compare true, it executes the code like a typical if statement.

But what if I accidentally assign a value greater than 2 to…

Animating a sprite in Unity is wonderfully simple to implement, once you have the art.

Here is the speed powerup from the Gamedevhq 2D game course. It’s got the first frame of the animation I want to give it, set in the sprite renderer.

Kasper Møberg Rasmussen

Masters graduate of Learning and experience technology from University of southern Denmark, with a passion for the future of interaction.

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