- Home /
Duplicate Question
CountDown Timer in 2D
hi, I'm new to C# and unity 2D. I'm making game like hill climb racing, and I'm stuck in making countdown timer. In my game, player will game over when time is over.
any ideas?
Thanks, Tio.
in which part did you stuck? creating a timer or showing it?
Well, give it a try and then show your code in a question here if you get stuck, but the way you are asking the question now is like you want someone to code your timer for you..
There are a number of ways that you can approach a timer, in my personal opinion, I think a coroutine would be a good option:
https://docs.unity3d.com/Documentation/ScriptReference/Coroutine.html http://docs.unity3d.com/Documentation/$$anonymous$$anual/Coroutines.html
Start the coroutine in the start function and you can use:
yield return new WaitForSeconds(1);
within a while loop to make it repeat your code every second, which could be a gui text countdown.. Anyways, good luck
Thanks for answer, but I have solved this problem. thankyou :)
Answer by PvTGreg · Mar 06, 2014 at 07:42 AM
simple google search and i found this http://answers.unity3d.com/questions/225213/c-countdown-timer.html
Answer by ejpaari · Mar 06, 2014 at 07:44 AM
This question has been asked quite many times. See for example the following questions
Actually, you can just use a simple timer script. using UnityEngine; using System.Collections; public class Whatever: $$anonymous$$onobehaviour { public float time = 100f; void Update() { time = time - Time.deltaTime; // This is the main part of the timer! Debug.Log("Time: "); Debug.Log(time); // Timer is initiated (whatever that means) } }