Unity计时的方法

方法一:倒计时


  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()方法每帧调用。

猜你喜欢

转载自blog.csdn.net/xiaoer1989124/article/details/80777777