方法一:倒计时
public IEnumerator Timer(float totaltime)//倒计时方法 { textTime.text = totaltime.ToString(); while (totaltime >= 0) { yield return new WaitForSeconds(1); textTime.text = totaltime.ToString(); totaltime--; } }
时间长短不一定为1秒,按需改变,直到时间为0,协程结束。
方法二:
void TimeCount() { timeUse += Time.deltaTime; }这个方法可以在Update()方法每帧调用。