如果语句停止完全运行

时间:2015-09-27 21:59:47

标签: c# unity3d

所以我写的应该是一个简单的程序,但我遇到了一个错误。我不确定发生了什么但是尽可能接近,程序将完全运行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");
    }
}

代码应该做的是等待一个触发器,这是游戏世界中一个物体向下移动一定量,然后它会产生四个预制件中的一个向下一段距离,从而创造一个无限的游戏。这个代码每次运行都没有完全杀死我的计算机的唯一原因是,我有一个补丁脚本,可以在距离触发器对象一定距离内删除游戏对象。

1 个答案:

答案 0 :(得分:0)

prevLocation = currentLocation;

需要

prevLocation = Mathf.Abs(currentLocation);

相关问题