1、具体代码入下:public Text TimeLabel;//时间显示Labelfloat sumT足毂忍珩ime;//总时间//协程倒计时public IEnumerator startCountDown(){while (sumTime >= 0){sumTime--;TimeLabel.text="Time:"+sumTime;if (sumTime == 0){//当游戏时间用完则游戏结束 Debug.Log("gameOver"); }//每隔一秒调用一次yield return new startCountDown(1); }}
2、使用方法,将本代码复制到你的工程里,在Start函数里使用StartContinue(startCountDown);启动协程进行倒计时。