bool tryToSpawnUnit(UnitToSpawn unitToTryToSpawn) { if (unitToTryToSpawn.timeBeforSpawn <= time) { GameObject newUnit = Instantiate(unitToTryToSpawn.unit); newUnit.transform.position = unitToTryToSpawn.position; newUnit.GetComponent <Soldat>().camp = unitToTryToSpawn.faction; newUnit.transform.parent = unitsContainer.transform; newUnit.GetComponent <Soldat>().element = unitToTryToSpawn.element; newUnit.GetComponent <Soldat>().chemin = unitToTryToSpawn.chemin; newUnit.GetComponent <Soldat>().etape = unitToTryToSpawn.etape; return(true); } else { return(false); } }
void startRound() { GameObject[] barracks = GameObject.FindGameObjectsWithTag("barrack"); foreach (GameObject barrack in barracks) { Baraquement barrackScript = barrack.GetComponent <Baraquement>(); for (uint index = 0; index < barrackScript.nbUnitToSpawnPerRound; ++index) { UnitToSpawn unitToSpawnToAdd = new UnitToSpawn(); unitToSpawnToAdd.unit = barrackScript.unitToSpawn; unitToSpawnToAdd.position = barrack.transform.position; unitToSpawnToAdd.faction = barrackScript.camp; unitToSpawnToAdd.element = barrackScript.element; unitToSpawnToAdd.chemin = barrackScript.chemin; unitToSpawnToAdd.etape = barrackScript.etape; unitToSpawnToAdd.timeBeforSpawn = index * barrackScript.spawnInterval; unitsToSpawn.Add(unitToSpawnToAdd); } } ++nbRound; time = 0; }