I wrote another tutorial targeted towards beginners in Unity. In this short tutorial we will make a easy to use cooldown timer that can be used for things such as abilities, spawners, and much more. We will also make a small project to see the timer in action.
There is a github project available here and you can view the tutorial here (in text!).
Just want to help contribute to the Unity community, any suggestions and comments are always appreciated. Hope this helps someone!
Some useful additions to this script would be to have a public method to start it all off:
public void ActivateCooldown();
Then you could also have some public events, like so:
public Event NotifyNotReady;
public Event NotifyReady;
That first event would fire if you attempted to call ActivateCooldown() before it was ready, and the second one could be called the moment the cooldown timer expires and the end user actually COULD call the ActivateCooldown() method again.
The first event could be used to make a “Bzzzt!” negative sound, and the second event could be used to turn a button back on and/or make a “ding! your spell is ready!” sound.
And by using events, it makes it so that game behavior can be changed directly from the Unity editor!
Thanks for reading and for the comments! Both are very useful suggestions.
The cooldown can be toggled through the bool, however it would be useful to have an activate function to add any other initialization work that needs to be done.
I didn’t add anything about Events since this was mostly targeted for beginners, but I will add a little about them to the end, since they are very useful but may be out of scope for people just getting started.