Countdown Timers

Hey guys

I’ve been using Unity’s tutorials on how to create a Ball Game in C#, where they explained on how by picking objects up, counts numbers up and when it hits the desirable amount, you win the game :slight_smile:

But what if i wanted to create a countdown timer, so when it reaches 0, the GUItext says “game over”

Like the score system where i coded

public class PlayerController : MonoBehaviour 
{
	public float speed;
	public GUIText countText;
	public GUIText winText;
	public GUIText timerText;
	private int count;

	void Start ()
	{
		count = 0;
		SetCountText ();
		winText.text = "";

	}

Count here starts at 0, when this hits 10 (When the player collects 10 pickups) YOU WIN! can I do this with time?

I want it so that it is displayed, starts off… as a minute, and as soon as it hits 0, the game is over! But if the player collects 10 pickups before the time runs down, they still win!

Im pretty new to programming, so ive been racking my brains about this, but no hope! Any help is appreciated! Thank you <3

Also , in C# too, as the tutorial was in C# so javascript is useless for me :frowning:

First up C# and JavaScript aren’t that bad to convert between. Just go to the docs.

Essentially what you are after is a timer. Here is a basic one, adjust as needed.

private float timer = 0;

void Update (){
    timer += Time.deltaTime;
    if (timer > 10){
        // Do something
    }
}

Coroutines can also be used to achieve the same effect