Simple Cooldown Mechanic in Unity 2021

The above script makes use of the new Input System.
Make sure the Input System package has been imported into the project.

By tracking when the player last fired the weapon, the current time, and checking the difference, we can make a very simple cooldown system as shown above.

Before implementing the actual firing mechanic which is separate from the cooldown system, we can use Debug.Log to check that our cooldown mechanic is working as expected.

Code Cleanup
With our code in a working state, we can clean it up by dividing it up into logical sections with their own methods as shown above.

I’ve also condensed the code to reduce the number of lines used.

And that’s it, enjoy!



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