How to make my game stop once the timer meets zero in unity.

I’m trying to make a countdown timer, that ends the game once the timer meets zero.

public class StartGame : MonoBehaviour
{

    public float timeLeft = 3.0f;
    public Text startText; // used for showing countdown from 3, 2, 1 


    void Update()
    {
        timeLeft -= Time.deltaTime;
        startText.text = (timeLeft).ToString("0");
        if (timeLeft <= 0)
        {
            GameOver();
            timeLeft = 0;
            
        }
    }

    public void GameOver()
    {
        Application.Quit();
    }
}

Hello.

For your Post, your code and your comments, I understand nothing.

This code does exactly what you are asking for,

Post closed.

Hello there.

I dont get whats the problem. This code should work.

Well, it not stops the game, it quits the game. What do ou mean with stop? Tou can make all things depending on time to stop with Time.timeScale=0…

Does that script not work or do you want to just change scenes ?