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

How to build a GraphQL Server using Laravel — Part 1

Scraping Table Data From Websites— using a single line in Python

Tutorial Fuzzy Logic Mamdani for Arduino

Tutorial Fuzzy Logic Mamdani for Arduino

Haking MetaSploit — Part 1

Primitive Data Types in Java

Research On Dynamic Programming

Simulating Air Traffic With Azure

Migration From WordPress To JAMstack — A Complete Guide

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

OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Creating Attack Script and Collision Layers!

Variables! — The building blocks of programming

Zoo Cards as Scriptable Objects