Limiting the Player: an Ammo System (Game dev Day 35)

Serialize the field if you want to easily change the player’s ammo from the Inspector.
Adding onto the script from previous articles.
Same logic we used for the laser sound effect.
Lots of variables here, but we only care about the bottom two right now.
Same image as before, now with context.
Feel free to play around with color, size, and position of the UI element. We all have our preferences.
Easy to see, and it stands out!
This is in the UIManager script.
This will change the content of the UI element to match whatever math we do it.
The UI manager is now being called to update the ammo counter.
Make sure you place that Ammo_Display object in the Hierarchy into the script to link it all up.
The ammo counter goes down with each shot.
Pressing Space did not produce any lasers once the counter read 0.
Listen for the no ammo sound effect.

--

--

--

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Contributing to The Arctic Code Vault.

Algorithms in programming

Kong + OAuth2.0 + Keycloak -Bearer only Client and JWT

Consequences of Violating Google Play Policies

Google Play developer policies

Window 10 Shortcut Keys

Why I Wouldn’t Use Firebase Analytics In My Next Project

Movement in Unity — always the best part!

How Laravel Nova is easily integrated with Vapor S3 File Upload and Media Library

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
Jack Leavey

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!

More from Medium

How to Play Sound Effects in Unity

Journal 146 — Unity Project Development, 2.5D Shooter

RTS Interlude #4: Improving the healthbars (Unity/C#)

Cinemachine and Group Targets in Unity