yield return new WaitForSeconds(waitTime) 在 Time.timeScale=0下卡死

例如下面代码:

IEnumerator f(){

  Time.timeScale = 0;

 

  float waitTime=2;

  yield return new WaitForSeconds (waitTime);

  Debug.Log(“hi”);

}

则“hi”永远输不出来。

欲在Time.timeScale=0的情况下wait一定时间,可用如下代码:

IEnumerator f(){

  Time.timeScale = 0;


  float waitTime = 2;
  float t = 0; 
  while(true){
    if(t==waitTime)break; 
    t+=Time.unscaledDeltaTime;
    t=Mathf.Min (t,waitTime);
    yield return null;
  }

  Debug.Log(“hi”);

}

你可能感兴趣的:(yield return new WaitForSeconds(waitTime) 在 Time.timeScale=0下卡死)