countdown timer script

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

It would look something like this [c#]:

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

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

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

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";
        }

    }

}

Nice…

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