- Home /
Display countdown timer in Unity: distance traveled C#
I'm new to C# and Unity. I'm making a game with a countdown timer. The timer counts the distance you've traveled so the timer is linked to the player. I'm using the following script:
public class PlayerPhysics : MonoBehaviour {
private int countdownTimer = 10000;
if (!movementStopped) {
countdownTimer = countdownTimer -10;
if (countdownTimer == 0) {
Debug.Log("Message is written");
}
}
The script is working, but i wonder how i can display the timer in Unity so the actual player can see how many steps are still left to take.
Answer by zee_ola05 · Feb 05, 2014 at 12:01 AM
You can use the built-in GUI system of Unity using OnGUI()
. But for me, it can only be used as placeholders since it is not good-looking. The most popular GUI system for Unity is the NGUI as it makes GUI very easy to do. However, the author stopped updating it recently because he was hired by Unity to create the new built-in Unity GUI (uGUI). It is now under beta and is coming soon. You should wait for it. Or practice with NGUI since I heard it will be very similar. Or just use OnGUI()
as placeholder.
void OnGUI()
{
GUI.Label(new Rect(0,0 100,100), "countdown: " + countdown);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613132551im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
countdown/countup timer 1 Answer
How to stop a Countdown Timer? 1 Answer
Timer not work :( 0 Answers