unity:倒计时

int Min = 6;//分钟
int Stime = 0;//


IEnumerator CountDown()
    {

        while (Stime > 0)
        {
            timer.GetComponent<Text>().text = "0"+Min.ToString() +":"+ Stime.ToString();
            yield return new WaitForSeconds(1);
            Stime--;

        }
        while (Stime == 0)
        {
            timer.GetComponent<Text>().text = "0" + Min.ToString() + ":" + Stime.ToString()+"0";
            yield return new WaitForSeconds(1);
            Stime--;

        }
        while (Stime < 0)//秒减到0以后重新调用协程,分钟数减去1
        {
            Min--;
            Stime = 59;

            StartCoroutine(CountDown());
        }
    }
莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
原文地址:https://www.cnblogs.com/huang--wei/p/11133748.html