Creating a cool-down system in Unity

We have the following objective:

Create a variable cool-down system.

We need to know if two seconds has passed. Unity has a built in function which lets you get this information:

Time.time

This method let’s you detect and know how many seconds have passed.
The value of Time.time is how long the game has been running. This information is given back to you in seconds.
Example: 300 = 5 minutes

We need to create two variables. One variable to check the passed time, the other one for the actual cooldown delay time.

_nextFire will determine if 2 seconds have passed.

If the required amount of time has passed, we will be able to fire the laser. Doing so will re-assign _nextFire to the current time and add a cool down delay.

Here’s how a successful implementation should look like:

--

--

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
Timo Schmid

Timo Schmid

46 Followers

The mission? Becoming a game developer! RPG is the dream! Writing down my journey here for me and for everyone interested. Thanks for showing interest :)