If语句完全停止运行
本文关键字:运行 语句 If | 更新日期: 2023-09-27 18:14:50
所以我写什么应该是一个简单的程序,但我遇到了一个错误。我不确定发生了什么,但就我所知,程序将完全运行if语句一次,然后再也不运行整个代码块了。我完全不知道我的错误在哪里。
void Update () {
checker = Mathf.Abs (wheel.transform.position.y) - prevLocation;
if (checker > 1.9) {
Debug.Log (checker + "checker");
pick = Random.Range (0,5);
rotation = Random.Range (0,360);
currentLocation = (int) wheel.transform.position.y;
switch(pick){
case 1:
Instantiate(half, new Vector3(0, count, 0), Quaternion.Euler (new Vector3(-90, rotation, 0)));
break;
case 2:
Instantiate(threequarter, new Vector3(0, count, 0), Quaternion.Euler (new Vector3(-90, rotation, 0)));
break;
case 3:
Instantiate(halfB, new Vector3(0, count, 0), Quaternion.Euler (new Vector3(-90, rotation, 0)));
break;
case 4:
Instantiate(quarter, new Vector3(0, count, 0), Quaternion.Euler (new Vector3(-90, rotation, 0)));
break;
}
prevLocation = currentLocation;
Debug.Log (prevLocation + "prev");
checker = 0;
count = count - 2;
Debug.Log (count + "count");
}
}
代码应该做的是等待一个触发器,即游戏世界中的一个物体向下移动一定数量,然后它将在一定距离下生成四个预制件中的一个,从而创造一个无限的游戏。每次我运行这段代码时,这段代码没有完全杀死我的电脑的唯一原因是,我有一个补丁脚本,可以删除距离触发对象一定距离的游戏对象。
prevLocation = currentLocation;
必须是
= Mathf.Abs(currentLocation);