- Home /
Question by
mingoy_justin · Jan 12, 2021 at 09:34 AM ·
timer countdown
How to add different countdown timer?
Im trying to make a 3 countdown timer but when i press a button all of them decreases at the same time. each countdown timer has a different length of time. 15, 30 and 22 seconds void Update() { timer -= 1 Time.deltaTime; timer15currenttimer -= 1 Time.deltaTime; }
void OnGUI()
{
if (exer == "30")
{
timer = 30f;
tresttiemr.text = timer.ToString("0");
}
if (exer == "15")
{
countdownText.text = timer15currenttimer.ToString("0");
}
}
public void fb()
{
exer = "30";
OnGUI();
}
public void sb()
{
exer = "15";
OnGUI();
}
this is what i use to try it.
Comment
Answer by Llama_w_2Ls · Jan 12, 2021 at 09:44 AM
You could use coroutines instead, for example:
IEnumerator CountDownTimer(int seconds)
{
int TimeRemaining = Seconds;
while (TimeRemaining > 0)
{
TimeRemaining -= 1;
yield return new WaitForSeconds(1);
}
}
And then call them like:
public void Start15SecTimer()
{
StartCoroutine(CountDownTimer(15));
}
Remember to use System.Collections
Your answer
Follow this Question
Related Questions
How do I make a Countdown Timer in Minutes and Seconds only 1 Answer
countdown timer 0 Answers
making a timed kill combo counter 0 Answers
how to put a timer on my game 1 Answer