How To Create A Depletable Energy Meter

Depending on what kind of energy you may be wanting in your game, you may do this in various ways. All in all, it’s actually quite simple to pull off.

To start, you will have to create either an int or a float variable within your script. This number value will represent the amount of energy left in your meter. For this example, I will be using a value of 100 so that it can be easily equatable to percentages (%).

This works for a system that drains your energy (_mana) by set amounts.

But what if you wanted it to drain incrementally over time?

This example uses a Coroutine to drain the player’s mana by 1 every .05 seconds while holding down the “Left Shift” button to cast a spell.

It’s that easy! You can use systems like this to create health mechanics, stamina, energy, jet fuel, etc. In the GIF below you, you can see the player ship begin moving at an increased speed as I hold down the Left Shift button and at the same time you see the fuel gauge in the upper left corner decrease.

--

--

--

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

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

Recommended from Medium

Epicenter announces EPIC League Season 3

img

Donut County: Parts of a Hole

if you are a new gamer for RUNESCAPE you need review this guide

Sony swung for the fences with the PlayStation E3 2018 keynote

The Sims Creator Will Wright Launches NFT driven game Proxi

MDA: SPIT/SPEED/SLAM

Team Secret wins Gamers Without Borders 2020 charity tournament

img

Starsharks&0xAdventure

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
Adam Reed

Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!

More from Medium

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 2)

Mastering Unity Scripting | Summary — Chapter 2: Debugging

Overloading methods in C# & Unity

MVC Pattern in Unity — Less Code Dependency and Better Code Architecture