Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一。当值为2时,控制变量导致循环_C#_Unity3d - Fatal编程技术网

C# 统一。当值为2时,控制变量导致循环

C# 统一。当值为2时,控制变量导致循环,c#,unity3d,C#,Unity3d,我有这段代码,当变量waveNumer等于1时,代码工作正常,生成敌人等等,但当is 2 Unity崩溃时。我猜这是进入一个堰环,但我不明白为什么它会发生 int percentForWave=0; int percentForType=0; int TotalEnemies = (int)enemySpawnsThisRound; if (waveNumer == 1) { Debug.L

我有这段代码,当变量waveNumer等于1时,代码工作正常,生成敌人等等,但当is 2 Unity崩溃时。我猜这是进入一个堰环,但我不明白为什么它会发生

        int percentForWave=0;
        int percentForType=0;

        int TotalEnemies = (int)enemySpawnsThisRound;
        if (waveNumer == 1)
        {
            Debug.Log("Entro al wave 1");
            percentForWave = 20;
            percentForType = 20;
            startList = 0;

        }
        if (waveNumer == 2)
        {
            Debug.Log("Entro al wave 2");
            percentForWave = 70;
            percentForType = 70;
            startList = endList;

        }
        if (waveNumer == 3)
        {
            Debug.Log("Entro al wave 3");
            percentForWave = 10;
            percentForType = 10;
            startList = endList;
        }


        int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * ((decimal)percentForWave / 100), 1));
        int enemiesForType = Decimal.ToInt32(Math.Round(lenghtList * ((decimal)percentForType / 100), 1));


        endList = enemiesForType + startList;

        clonesASpawnear = new GameObject[enemiesThisWave];
        int i = 0;

        while ( i < clonesASpawnear.Length)
        {



            for (int j = startList; j == endList; j++)
            {
                Debug.Log("Numero j = " + j);
                if (clonesASpawnear[i] == null)
                {

                    clonesASpawnear[i] = Instantiate(enemyTypeList[j], spawnPoints[j].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                    clonesASpawnear[i].SetActive(true);//lo activo
                    clonesASpawnear[i].GetComponent<EnemyMovement_DCH>().player = Target;
                    aliveEnemies += 1;
                    clonesASpawnear[i].GetComponent<EnemyDamageHandler_DCH>().SpawnerEnemies = this;
                    i++;
                }



            }   

        }         
int percentForWave=0;
int percentForType=0;
int Total敌军=(int)敌人本轮攻击;
如果(waveNumer==1)
{
调试日志(“Entro al wave 1”);
波的百分比=20;
percentForType=20;
惊吓者=0;
}
如果(waveNumer==2)
{
调试日志(“Entro al wave 2”);
波的百分比=70;
percentForType=70;
惊吓者=结束列表;
}
如果(waveNumer==3)
{
调试日志(“Entro al wave 3”);
波的百分比=10;
percentForType=10;
惊吓者=结束列表;
}
int ENEMIESTHISWEET=Decimal.ToInt32(数学四舍五入(TotalForWave*((十进制)百分比/100),1));
int-enemiesForType=Decimal.ToInt32(数学四舍五入(lenghtList*((十进制)percentForType/100),1));
endList=enemiesForType+startList;
clonesASpawnear=新游戏对象[敌人的浪潮];
int i=0;
而(i

如果我能在程序崩溃后看到unity日志,但不知道如何做到这一点,这也会很有用

从这里我可以看到,我在for循环的条件语句中看到了一个问题,请看这里

for(int j=startList;j==endList;j++)

在您的情况下,您只能得到一个值,即
true
。当j的值等于endList时,因为在for循环中
j
每次迭代都会递增,所以您的条件只会在一次迭代中为真,根据您的判断,这是第一次迭代。如果for循环不会迭代
i
的值,它是外部while循环的一个控制变量,永远不会增加hance,那么while循环将进入无限状态,永远不会停止迭代,一切都会冻结并崩溃

正如我在评论中看到的,当
j=1

我想知道崩溃时几个变量的值

  • clonesASpawnear.长度
  • 惊吓者
  • 结束列表

    • 我们最终以这种方式解决了这个问题。我张贴解决方案,以防有人陷入同样的困境

       while ( i < clonesASpawnear.Length)
          {
      
      
              if(j <= endList)
              {
                  Debug.Log("Numero j = " + j);
                  //se fija que ya no este en el escenario el que va en ese punto asi no superpone items
                  if (clonesASpawnear[i] == null)
                  {
      
                      clonesASpawnear[i] = Instantiate(enemyTypeList[j], spawnPoints[j].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                      clonesASpawnear[i].SetActive(true);//lo activo
                                                         //Aca le asigno el blanco que quiero que siga al spawnear
                      clonesASpawnear[i].GetComponent<EnemyMovement_DCH>().player = Target;
                      aliveEnemies += 1;
                      //aca le asigno este spawner para que pueda afectar luego las variables cuando lo maten por ejemplo
                      clonesASpawnear[i].GetComponent<EnemyDamageHandler_DCH>().SpawnerEnemies = this;
      
                  }
                  j++;
                  i++;
              }
              else
              {
                  j = startList;
              }
      
      
      
      
      
      
      
           Debug.Log("Numero i = " + i);
      
          }
      
      
      
      }
      
      while(i如果(j)“它崩溃了”不是一个足够的问题描述。异常消息是什么?调试器说它来自哪一行?乍看之下,我怀疑您想要的是jj
      for循环将使您更接近您想要的。在崩溃时,我看不到任何值。没有打印日志,但这让我充分了解了什么是错误,可以继续b我自己,所以很多!