我快疯了。对于我的生活,我不知道为什么下面的代码是导致团结冻结,只要我按下播放。它是一个原本是空的项目,脚本附加到一个空的游戏对象。在控制台中,什么都没有出现,甚至连初始的Debug.Log("Step 1");都没有出现。
using UnityEngine;
public class Reels : MonoBehaviour
{ void Start()
{
Debug.Log("Step 1");
TestFunction(1f);
}
private void TestFunction(float duration)
{
float endTimer = Time.time + duration;
Debug.Log("Step 2 " + endTimer);
while (Time.time < endTimer)
{
Debug.Log("Step 3");
}
}
void Update()
{
}
}请拯救我的理智。
发布于 2022-05-03 19:22:49
Time.time是在帧的开头存储时间。的只读字段,按照您编写代码的方式,框架永远不会结束,因为您将永远无法脱离这个循环。
https://stackoverflow.com/questions/72104431
复制相似问题