Creating A Cooldown System in Unity

In this challenge I have a Player that can shoot when I press the space key, the only detail is without any restriction the player can shoot a lot of lasers.

To avoid this overpowering behaviour we should create a cooldown system, in this case after the player shoots we have to wait some time to shoot again.

To achieve this first we gonna create a fireRate variable and a bool canShoot:

Then we gonna create a coroutine in this case will be the cooldown function:

As well we have to add the can shoot variable when we detect the space key:

After create the coroutine we have to call it in the shooting function with the method StartCoroutine:

And that’s it a completely functional cooldown system:

The cooldown system is used in many other games for example Among us have cooldown each time you kill a crewmate as an impostor or in Call of Duty when you receive damage you have to wait some time to heal.

--

--

--

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

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

Recommended from Medium

Use Nvidia-Docker to never worry about installing a specific version of a framework again

Power BI — Incremental refresh

Adding Animation Track to a Timeline in Unity

CI4 launches web development app only on its current release and rework — refactor set on the stage.

Learning Go: Object-Oriented Programming Part 1

Network Management Systems in Bridgend #Network #Performance #Monitoring #Bridgend https://t.co/nZX6

Amazon S3’s PUT Bucket API cannot accept “us-east-1” region

How Do Apps Connect To My Bank Account?

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
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

More from Medium

Quick tip — Enabling post-processing in Unity Universal Render Pipeline

Creating An fbx Emission Layer For Unity Using Photoshop & Blender

What are “Render Pipelines” in Unity?

Sci-fi Lab — Collider