void SpawnSubCreep(UnitCreep prefab, float orHP = -1, float orSH = -1, float orSpd = -1, int orRscExp = -1, List <int> orRsc = null) { Vector3 dir = (subPath[subWpIdx] - GetPos()).normalized; Vector3 spawnPos = GetPos() + dir * Random.Range(-.5f, .5f); //~ GameObject unitObj=(GameObject)Instantiate(prefab.gameObject, spawnPos, thisT.rotation); GameObject unitObj = ObjectPoolManager.Spawn(prefab.gameObject, spawnPos, thisT.rotation); UnitCreep unitInstance = unitObj.GetComponent <UnitCreep>(); unitInstance.SetHP(orHP); unitInstance.SetSH(orSH); unitInstance.SetSpeed(orSpd); if (orRsc != null) { unitInstance.rscGainOnDestroyed = orRsc; } //~ if(orHP>0) unitInstance.SetHP(orHP); //~ if(orSH>0) unitInstance.SetSH(orSH); //~ if(orSpd>0) unitInstance.SetSpeed(orSpd); //~ if(orRsc!=null) unitInstance.rscGainOnDestroyed=orRsc; unitInstance.Init(waveIdx, path, wpIdx, subWpIdx, false, reverse, new List <Path>(prevPathList), subPath); SpawnManager.SubUnitSpawned(unitInstance); //SpawnManager.SubUnitSpawned(unitInstance, waveIdx); }
public UnitCreep SpawnUnit(UnitCreep creep, int waveIdx, Path path, SubWave subWave = null) { //~ GameObject unitObj=(GameObject)Instantiate(creep.gameObject, path.GetSpawnPoint(), Quaternion.identity); GameObject unitObj = ObjectPoolManager.Spawn(creep.gameObject, path.GetSpawnPoint(), Quaternion.identity); UnitCreep unitInstance = unitObj.GetComponent <UnitCreep>(); unitInstance.ResetHP(); unitInstance.ResetSH(); unitInstance.ResetSpeed(); unitInstance.ResetRscGainOnDestroy(); if (subWave != null) { //if(subWave.HP>0) unitInstance.SetHP(subWave.HP); //if(subWave.SH>0) unitInstance.SetSH(subWave.SH); //if(subWave.speed>0) unitInstance.SetSpeed(subWave.speed); //if(subWave.overrideRscGain) unitInstance.rscGainOnDestroyed=subWave.rscGain; unitInstance.SetHP(subWave.HP > 0 ? subWave.HP : -1); unitInstance.SetSH(subWave.SH > 0 ? subWave.SH : -1); unitInstance.SetSpeed(subWave.speed > 0 ? subWave.speed : -1); unitInstance.SetRscGainOnDestroy(subWave.overrideRscGain ? subWave.rscGain : null); } else //reset the unit value to default value { unitInstance.SetHP(); unitInstance.SetSH(); unitInstance.SetSpeed(); unitInstance.SetRscGainOnDestroy(null); } unitInstance.Init(waveIdx, path); totalCreepCount += 1; unitInstance.instanceID = totalCreepCount; return(unitInstance); }