Reload ammo during the game!

Objective: create a collectable to add more ammo when the player collects it

First I dropped a sprite in the scene, modified the size and added the components (collider and rigidbody) to create the ammo prefab.

Also I added the powerup script to this prefab because it is gonna have the same behaviour than a powerup. The player collects it and executes something.


Limiting the number of lasers

Objective: set a limited number of laser the player can shoot

To start I declared in the player script an int variable calle “_ammo” to determine the quantity of laser the player can shoot. Then each time the player shoots we decrement the value of the variable by 1 and next I added a conditional to check if the ammo is 0 then the player can not shoot.

The ammo feature is working but the player doesn’t know how many lasers can shoot. So let’s add some UI.


Improving the shield powerup

Objective: Make Shield take up to 3 hits and change the color in every time it is damaged

The original shield consisted of a game object disabled and once the player picked the powerup we activated it until the player was damaged.

In order to create this feature I made the shield a prefab and deleted it from the player.

Then I created a variable in the player script to have the reference to the prefab and wrote a function to Instantiate a shield.


Make player faster

Objective: activate thruster when player presses the shift key

In this challenge we are gonna give the player a speed boost when he presses the left shift key and deactivate the thruster when he releases the key.

We have to create a variable to have the reference to the thruster object (and assign it in the inspector) and another variable to manage the extra speed for the player.


Publishing your game on Internet

Objective: Publish a WebGL Unity Build on Itch.io

Ok let’s say you have your game ready you have to submit your entry for a game jam or any case where you need to publish that game on the Web. In this example we are gonna use Itch.io as a platform to publish our game.

First thing is to have the WebGL Build ready, if you don’t know how to create it I leave you the next link to an article that explain how to do that:

https://rusbenguzman.medium.com/how-to-build-and-test-your-unity-game-aa650cc58cdf

Now you have to sign in in your itch.io …


Exit game with the escape key

Objective: Exit game when user presses the escape key

I’m gonna add a feature to exit the game when the player presses the escape key. In order to do that I add the following code in the GameManager script within the Update function.

If you want to quit the game from the unity editor, you have to uncomment the line UnityEditor.EditorApplication.isPlaying = false.

And that’s all! You can exit game using the escape key.


Creating the executable files to test the game without the Unity editor

Objective: Use the build option to create the files to test the game on the computer.

Unity the “Build” option to create the necessary files to play or test the game on a specific platform. In order to do that the first step is go to “File > Build Settings”.


Powerup indicator!!!

Objective: Play a sound effect when the player collects a powerup

Now It is time for the powerups. First I created an empty game object called PowerupAudio as a child of the Audio Manager, unchecked the “Play On Awake” attribute and assigned the clip.

Then in the player script I created an AudioSource variable and assigned the reference in the Inspector. Next I created a public function to play the sound.


Adding a Boom! SFX

Objective: Add an Explosion SFX when Player/Enemy/Asteroid explodes.

In this case we have different objects with the same SFX so let’s get into it. First I Added an AudioSource component to the “Explosion” prefab, checked the “Play On Awake” and assigned the audio clip.

This works for the asteroid because the sound is gonna be played when the explosion prefab is instantiated.


Adding an audio for the player shoot action

Objective: Play a laser sound effect when the player shoots.

I opened the “Laser” prefab and added an AudioSource component, checked the “Play On Awake” attribute and added the clip to the AudioClip.

That’s it! In this case we don’t have to do anything else, when the player instantiates a laser the sound is gonna play automatically because the “Play on Awake” attribute allows to play the SFX when the GameObject is created.

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

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