用unity做了一个2D游戏,时间倒计时到0时,怎么游戏停止。

我的代码现在是这样,30秒的倒计时,30秒后 就开始-1,-2,-3游戏还在继续 没有结束
想问一下 这种情况怎么处理
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class countdown : MonoBehaviour
{
public float timeStart = 30;
public Text textBox;

bool timerActive = false;

// Start is called before the first frame update
void Start()
{
    textBox.text = timeStart.ToString();
}

// Update is called once per frame
void Update()
{
    if (timerActive) {
        timeStart -= Time.deltaTime;
        textBox.text = Mathf.Round(timeStart).ToString();
    }
   
}

public void startBtn() 
{
    timerActive = !timerActive;
}

}


    /// <summary>
    /// 退出游戏
    /// </summary>
    public static void ExitGame() {
        if (Application.isEditor)
        {
            //编辑器模式
            UnityEditor.EditorApplication.isPlaying = false;
        }
        else {
            Application.Quit();
        }
    }

在update判断倒计时<=0时,调用这个方法就可以推出游戏了

倒计时结束了调用函数Application.Quit();试试