C# 而Unity C中的循环使播放模式从不加载

C# 而Unity C中的循环使播放模式从不加载,c#,unity3d,C#,Unity3d,我制定了以下代码: public GameObject prefabBullet; public GameObject[] places; public int amountOfCycles; public float baseTimeBetweenCycles; public float timeBetweenCycles; private int amountOfCyclesThatAlreadyHappened; private int value = 0; private i

我制定了以下代码:

public GameObject prefabBullet;
public GameObject[] places;

public int amountOfCycles;

public float baseTimeBetweenCycles;

public float timeBetweenCycles;

private int amountOfCyclesThatAlreadyHappened;

private int value = 0;

private int random;

void Start() {
    random = Random.Range(0, places.Length + 1);
    amountOfCyclesThatAlreadyHappened = 0;
}


void Update()
{
    while(amountOfCyclesThatAlreadyHappened < amountOfCycles)
    {
        while(value < places.Length && timeBetweenCycles < 0) 
        {
            if(value != random)
           {
            GameObject bulletGO = Instantiate(prefabBullet, places[value].transform.position, Quaternion.identity);
            timeBetweenCycles = baseTimeBetweenCycles;
           }
           value++;
           break;
        }

            if(timeBetweenCycles > 0)
           {
            timeBetweenCycles -= Time.deltaTime;
           }

            if(value > places.Length)
           {
               amountOfCyclesThatAlreadyHappened += 1;
               random = Random.Range(0, places.Length + 1);
               value = 0;
           }
    }

}
我不认为我做了其中一个无限循环,因为它最终将值设置为0,并且两个LOP最终都应该停止为真,因为++存在于两个循环中。任何人都可以告诉我是什么导致了这些循环是无限的?

你的外部while永远在循环,因为amountofcyclesthatiready从来没有出现过增量

代码中唯一一个AmountofCyclesthatalReadyHappen可以增加的地方就是在这个例子中:ifvalue>places.Length

但是,这种情况发生在while循环中,条件是value 正如您所看到的,if和while条件具有与值相关的相反条件,因此内部if唯一可能为true的方法是在循环执行期间在命中if块之前更改if值。但是,唯一发生这种情况的地方是value++;,休息一下;紧跟其后,这样循环就不会继续了。

你的外部while将永远循环,因为amountofcyclesthathatlready似乎永远不会增加

代码中唯一一个AmountofCyclesthatalReadyHappen可以增加的地方就是在这个例子中:ifvalue>places.Length

但是,这种情况发生在while循环中,条件是value
正如您所看到的,if和while条件具有与值相关的相反条件,因此内部if唯一可能为true的方法是在循环执行期间在命中if块之前更改if值。但是,唯一发生这种情况的地方是value++;,休息一下;我真的不理解你说的话,我知道我忘了把a=I put<代替=<你不懂什么部分?我真的不理解你说的,我知道我忘了把a=I put<代替=<你不懂什么部分?