Hi, Unity Community! My question today is not too much of “what” to program, but a specific way of “how” to program. In the game I’m working on, the player will have abilities and ultimates that’ll have cooldowns within them such as games like Heroes of the Storm. Right now, in my script, I have multiple timers and timeStamps for each ability, and this gets my code a bit confusing. I figured that there has to be some simpler “object-oriented” way.
Lets say I have the following variables:
abilityTime = 4f; //The time the ability last
abilityCooldown = 12f; //The time you'll have to wait until you use the ability again
Right now I have Couroutines and IEnumerators everywhere which makes it a mess. I’d like to use functions in simple ways like:
Ability(); //Use ability
Cooldown(abilityTime); //Ability timer starts
Cooldown(abilityCooldown); //When timer ends, the cooldown starts
//From here, the player will be able to loop back up and use Ability() again
Depending on the character/ability, the cooldown may start as soon as the player uses the ability
Ability(); //Use ability
Cooldown(abilityCooldown); //Start cooldown for next time
Ultimates or special power abilities may work a bit differently. Unlike abilities, when the game starts, players will have to wait a certain amount of time before using the Power for the first time.
ultTime = 8f; //The time the power last
ultCooldown = 90f; //The time you'll have to wait until you can use the power
//When the game starts...
Cooldown(ultCooldown);
UltimateAbility();
Cooldown(ultTime);
//From here, it'll go back up and wait ultCooldown
Is there anyone who can guide me in structuring the functions like this, or what to have in the cooldown functions? It’s pretty tough in C# since you have to use Couroutines and then continue the abilities within those. It gets messy and confusing. I get that this question is pretty vague, so please reply with questions so I can provide more clarity. Thank you for any help!!