# countdown timer script

**URL:** <https://discussions.unity.com/t/countdown-timer-script/398771>\
**Category:** Scripting\
**Created:** [September 28, 2009, 4:26am UTC](https://discussions.unity.com/t/countdown-timer-script/398771 "2009-09-28T04:26:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon\_95406527](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon\_95406527](https://discussions.unity.com/u/anon_95406527)\
**Post date:** [September 28, 2009, 4:26am UTC](https://discussions.unity.com/t/countdown-timer-script/398771/1 "2009-09-28T04:26:58Z")

</div>

can someone point me the direction of a countdown timer script.basically what i want is that when the time reaches zero the level ends  
the time can be adjusted within unity

---

<div class="post-metadata">

**Author:** ![anon\_6917124](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@anon\_6917124](https://discussions.unity.com/u/anon_6917124)\
**Post date:** [September 28, 2009, 11:04am UTC](https://discussions.unity.com/t/countdown-timer-script/398771/2 "2009-09-28T11:04:07Z")

</div>

It would look something like this [c#]:

```auto
public float timeLeft = 50.0f;

public void Update()
{
	timeLeft -= Time.deltaTime;
	
	if (timeLeft <= 0.0f)
	{
		// End the level here.
	}
	
}

```

That should count down from 50 seconds down to zero, and you can adjust the time whenever you want

---

<div class="post-metadata">

**Author:** ![anon\_95406527](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon\_95406527](https://discussions.unity.com/u/anon_95406527)\
**Post date:** [September 29, 2009, 2:36am UTC](https://discussions.unity.com/t/countdown-timer-script/398771/3 "2009-09-29T02:36:42Z")

</div>

sorry for sounding dumb …i am an artist …

where do i plug this script

also i want the player to see the timer as well as it counts down

---

<div class="post-metadata">

**Author:** ![llde\_chris](https://avatars.discourse-cdn.com/v4/letter/l/ecae2f/32.png) [@llde\_chris](https://discussions.unity.com/u/llde_chris)\
**Post date:** [September 29, 2009, 7:52am UTC](https://discussions.unity.com/t/countdown-timer-script/398771/4 "2009-09-29T07:52:08Z")

</div>

Updated hogus’ code. Attach it to a GUIText object.

```auto
using System;
using System.Collections.Generic;
using UnityEngine;

public class Countdown : MonoBehaviour
{
    public float timeLeft = 50.0f;

    public void Update()
    {
        timeLeft -= Time.deltaTime;

        if (timeLeft <= 0.0f)
        {
            // End the level here.
            guiText.text = "You ran out of time";
        }
        else
        {
            guiText.text = "Time left = " + (int)timeLeft + " seconds";
        }

    }

}

```

---

<div class="post-metadata">

**Author:** ![anon\_6917124](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@anon\_6917124](https://discussions.unity.com/u/anon_6917124)\
**Post date:** [September 29, 2009, 9:36am UTC](https://discussions.unity.com/t/countdown-timer-script/398771/5 "2009-09-29T09:36:10Z")

</div>

Nice…

Sorry, I was being a bit lazy there. :roll:
