//actual spawning routine, responsible for spawning one type of creep only IEnumerator SpawnSubwave(SubWave subWave, Wave parentWave, int waveID) { yield return(new WaitForSeconds(subWave.delay)); int spawnCount = 0; while (spawnCount < subWave.count) { Vector3 pos; Quaternion rot; PathTD tempPath; if (subWave.path == null) { tempPath = defaultPath; } else { tempPath = subWave.path; } pos = tempPath.waypoints[0].position; rot = tempPath.waypoints[0].rotation; GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot); //Unit unit=obj.GetComponent<Unit>(); UnitCreep unit = obj.GetComponent <UnitCreep>(); if (subWave.overrideHP > 0) { unit.SetFullHP(subWave.overrideHP); } if (subWave.overrideMoveSpd > 0) { unit.SetMoveSpeed(subWave.overrideMoveSpd); } List <Vector3> waypoints = new List <Vector3>(); foreach (Transform pointT in tempPath.waypoints) { waypoints.Add(pointT.position); } unit.Init(waypoints, totalSpawnCount, waveID); //~ unit.Init(tempPath, totalSpawnCount, waveID); totalSpawnCount += 1; parentWave.activeUnitCount += 1; spawnCount += 1; if (spawnCount == subWave.count) { break; } yield return(new WaitForSeconds(subWave.interval)); } subWave.spawned = true; }
public void Dead() { //~ if(PerkManager.rscGainCreepChance>0 && Random.Range(0f, 1f)>=PerkManager.rscGainCreepChance){ //~ int[] val=new int[value.Length]; //~ for(int i=0; i<value.Length; i++){ //~ float modifier=1+PerkManager.rscGainCreepModifier[i]+PerkManager.rscGainModifier[i]; //~ float bonus=PerkManager.rscGainCreepValue[i]+PerkManager.rscGainValue[i]; //~ val[i]=(int)Mathf.Round((float)value[i]*modifier+bonus); //~ } //~ GameControl.GainResource(val); //~ } //~ else GameControl.GainResource(value); //value length is verified as soon as game start so it never exceed actual resource length if (PerkManager.rscGainChance > 0 || PerkManager.rscGainCreepChance > 0) { float randG = Random.Range(0f, 1f); float randC = Random.Range(0f, 1f); int[] val = new int[value.Length]; for (int i = 0; i < value.Length; i++) { float modifier = 1; float bonus = 0; if (randG <= PerkManager.rscGainChance) { modifier += PerkManager.rscGainModifier[i]; bonus += PerkManager.rscGainValue[i]; } if (randC <= PerkManager.rscGainTowerChance) { modifier += PerkManager.rscGainCreepModifier[i]; bonus += PerkManager.rscGainCreepValue[i]; } val[i] = (int)Mathf.Round((float)value[i] * modifier + bonus); } GameControl.GainResource(val); if (onGainResourceE != null) { GainResourcePos grp = new GainResourcePos(thisT.position, val); onGainResourceE(grp); } } else { GameControl.GainResource(value); if (onGainResourceE != null) { GainResourcePos grp = new GainResourcePos(thisT.position, value); onGainResourceE(grp); } } if (deadEffect != null) { ObjectPoolManager.Spawn(deadEffect, thisT.position, Quaternion.identity); } float duration = PlayDead(); StartCoroutine(Unspawn(duration)); //spawn more unit if there's one assigned if (spawnUponDestroyed != null) { SpawnManager.AddActiveUnit(waveID, spawnNumber); for (int i = 0; i < spawnNumber; i++) { //generate a small offset position within the grid size so not all creep spawned on top of each other and not too far apart float allowance = BuildManager.GetGridSize() / 2; float x = Random.Range(-allowance, allowance); float y = Random.Range(-allowance, allowance); Vector3 pos = thisT.position + new Vector3(x, 0, y); GameObject obj = ObjectPoolManager.Spawn(spawnUponDestroyed, pos, thisT.rotation); UnitCreep unit = obj.GetComponent <UnitCreep>(); unit.Init(path, SpawnManager.NewUnitID(), waveID); //resume the path currently followed by this unit unit.StartCoroutine(unit.ResumeParentPath(wpMode, wp, wpCounter, currentPS, subPath, currentPathID, subWPCounter)); } } }
//actual spawning routine, responsible for spawning one type of creep only IEnumerator SpawnSubwave(SubWave subWave, Wave parentWave, int waveID) { yield return(new WaitForSeconds(subWave.delay)); int spawnCount = 0; while (spawnCount < subWave.count) { Vector3 pos; Quaternion rot; PathTD tempPath; if (subWave.path == null) { tempPath = defaultPath; } else { tempPath = subWave.path; } pos = tempPath.waypoints[0].position; rot = tempPath.waypoints[0].rotation; GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot); //Unit unit=obj.GetComponent<Unit>(); UnitCreep unit = obj.GetComponent <UnitCreep>(); if (subWave.overrideHP > 0) { unit.SetFullHP(subWave.overrideHP); } if (subWave.overrideShield > 0) { unit.SetFullShield(subWave.overrideShield); } if (subWave.overrideMoveSpd > 0) { unit.SetMoveSpeed(subWave.overrideMoveSpd); } if (subWave.overrideLifeCost >= 0) { unit.SetLifeCost(subWave.overrideLifeCost); } bool overrideValue = false; if (subWave.overrideValue.Length >= 0) { foreach (float val in subWave.overrideValue) { if (val > 0) { overrideValue = true; } } } if (overrideValue) { unit.SetValue(subWave.overrideValue); } unit.Init(tempPath, totalSpawnCount, waveID); unit.pathLooping = pathLooing; totalSpawnCount += 1; parentWave.activeUnitCount += 1; spawnCount += 1; if (spawnCount == subWave.count) { break; } yield return(new WaitForSeconds(subWave.interval)); } subWave.spawned = true; }