How To Create A Cooldown System In Unity

A cooldown system is in essence, a timer. You are asking the system to freeze the ability for something to happen for (x) amount of time and then reinstating that ability.

To do something like that you could do a few things. One option is to use the “IEnumerator” coroutine and the “WaitForSeconds” function to allow for a set delay in which it will then wait for a certain amount of time before continuing on.

This can get expensive memory-wise if used too much though, so at times where it can be avoided, it is often better to go down a different route.

Another option is to use “Time.time” along with a couple of float values to create a measurement of time as it passes in relation to an action. Time.time is a measurement of how long the game has been running in seconds.

If you look at the code example below, you’ll see this logic used to create a time delay to control a player’s attack speed!

--

--

--

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

A Fix for Outlook Image Issues in HTML Email Campaigns

Gaming The Dino With ESP8266

How to configure the viewport?

Video vs Iorad

CS373 Spring 2022: Kristina Zhou

The Bash Scripting Tutorial, Part 5

Forecasting Walmart Quarterly Revenue — Pytorch LSTM Example

Adjusting a node’s published time when publishing through content moderation

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

Day 7: The Enemy

Unity: Adding and Removing Objects

Variables -The building blocks of programming.

Creating A Cool-Down System in Unity | SHMUP Shoot Mechanics