- Home /
I make a cooldown system. But when cooldown is over my skill is still working. How can i fix that?
Codes:
public float cooldown = 1;
public float cooldowntimer;
float currentAmount = 0f;
float maxAmount = 5f;
void Update()
{
if (cooldowntimer > 0)
{
cooldowntimer -= Time.deltaTime;
}
if (cooldowntimer < 0)
{
cooldowntimer = 0;
}
if (Input.GetKeyDown("z") && cooldowntimer == 0)
{
Slowmo();
cooldowntimer = cooldown;
}
}
void Slowmo()
{
if (Input.GetKeyDown("z"))
{
if (Time.timeScale == 1.0f)
Time.timeScale = 0.2f;
else
Time.timeScale = 1.0f;
Time.fixedDeltaTime = 0.02f * Time.timeScale;
}
if (Time.timeScale == 0.03f)
{
currentAmount += Time.deltaTime;
}
if (currentAmount > maxAmount)
{
currentAmount = 0f;
Time.timeScale = 1.0f;
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Using the timer as a condition 0 Answers
Formats of High Score 1 Answer
How can I blink a gameobject faster and faster? 1 Answer
how to add time to a countdown 1 Answer