Unity 由于脚本而冻结,但我不知道所述脚本有什么问题

Unity freezes because of script, but i don't know whats wrong with said script

请耐心等待,我是 Unity 的新手。 正如标题所暗示的,当这个脚本附加到主摄像头时,游戏引擎会冻结。

public class leftright : MonoBehaviour {
    public float boundaries = 3f;

    void Update () {
        while (Input.GetAxis("Mouse X") < boundaries && Input.GetAxis ("Mouse X") > -boundaries) {
            this.transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
        }
    }
}

我不认为这个脚本会造成无限循环,而且我无法检测到它有任何问题。

日志文本是 here, and the project is here

While(true) {
    //do stuff
}

您在 while 语句中使用的条件不能(也不会)根据循环的内容从 true 更改为 false,因此它将运行永远。

Update() 已经是一个循环,把它当作一个循环。

void Update () {
    if(Input.GetAxis("Mouse X") < boundaries && Input.GetAxis ("Mouse X") > -boundaries) {
        this.transform.Rotate(0, Input.GetAxis("Mouse X"), 0);
    }
}