//called to generate a spawn wave using the procedural generation parameter Wave GenerateWave(int waveIDX) { Wave wave=new Wave(); wave.waveID=waveIDX; wave.spawnArea=spawnAreaList[Random.Range(0, spawnAreaList.Count)]; wave.creditGain=startingCredit+creditIncrement*waveIDX; wave.scoreGain=startingScore+scoreIncrement*waveIDX; int subWaveCount=Random.Range(1, waveIDX); subWaveCount=Mathf.Clamp(subWaveCount, 1, maxSubWaveCount); subWaveCount=Mathf.Clamp(subWaveCount, 1, spawnUnitList.Count); List<int> countList=new List<int>(); for(int i=0; i<subWaveCount; i++) countList.Add(1); int totalUnitCount=unitCount+unitCountInc*waveIDX-subWaveCount; if(subWaveCount<=0) totalUnitCount=0; int count=0; while(totalUnitCount>0){ int rand=Random.Range(1, totalUnitCount); countList[count]+=rand; totalUnitCount-=rand; if((count+=1)>=subWaveCount) count=0; } List<Unit> unitList=new List<Unit>( spawnUnitList ); wave.subWaveList=new List<SubWave>(); for(int i=0; i<subWaveCount; i++){ SubWave subWave=new SubWave(); subWave.count=countList[i]; int rand=Random.Range(0, unitList.Count); subWave.unitPrefab=unitList[rand]; unitList.RemoveAt(rand); subWave.startDelay=0.5f; subWave.interval=Random.Range(1f, 2f); wave.subWaveList.Add(subWave); } return wave; }