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

Guild’s importance on Coinary’s Ecosystem

Deep Rock Galactic review

Terror Strikes Beneath

New Immortal Gear Sets Herald Major P2E Upgrades in HodlGod

Bingoman has left the bingo hall

Beefquest 002: Commanding units

How to think about game balance as part of narrative design (and why you should care)

Game changer: Atari and the dawn of video game culture

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

Devlog 28: Added A Charged Shot To My Game

Day 7: The Enemy

git it on the page!

Unity Camera Shake C#