public void GenerateRandomEnemy() { //generate a new spawn position Vector2 randomOnCircle = Random.insideUnitCircle.normalized; Vector3 position = new Vector3(randomOnCircle.x, 0, randomOnCircle.y) * (Random.Range(minEnemySpawnRadius, maxEnemySpawnRadius)); //instantiate a new enemy, parent it to the spawn Enemy newEnemy = Instantiate(standardEnemyPrefab, position, Quaternion.identity).GetComponent <Enemy>(); newEnemy.gameObject.transform.SetParent(transform); //choose a new random type and path EnemyType randomType = enemyTypes[Random.Range(0, numEnemyTypes)]; EnemyCurvePath randomPath = enemyCurvePaths[Random.Range(0, numEnemyCurvePaths)]; //set up the enemy with the type and path newEnemy.SetupEnemy(randomType, randomPath); //create a new healthBar and associate it with the new enemy newEnemy.SetupBars(healthBarCanvas); //name the enemy gameobject using his properties' shorthand designations newEnemy.gameObject.name = numEnemyToSpawn + " - " + randomType.GetShortHand(); //add the enemy to the list enemies.Add(newEnemy); //increment the enemy number numEnemyToSpawn++; }
//works very similarly to spawning a normal enemy with the exception that it //can spawn multiple bosses with a single method call IEnumerator GenerateBossWave() { bossWave++; bossesSpawning = true; bossesAlive = true; int bossesToSpawn = (bossWave + 1) / 2; for (int i = 0; i < bossesToSpawn; i++) { Vector2 randomOnCircle = Random.insideUnitCircle.normalized; Vector3 position = new Vector3(randomOnCircle.x, 0, randomOnCircle.y) * (Random.Range(maxEnemySpawnRadius - 1f, maxEnemySpawnRadius)); Enemy newBoss = Instantiate(standardEnemyPrefab, position, Quaternion.identity).GetComponent <Enemy>(); newBoss.gameObject.transform.SetParent(transform); EnemyType randomBossType = bossTypes[Random.Range(0, numBossTypes)]; EnemyCurvePath randomPath = enemyCurvePaths[Random.Range(0, numEnemyCurvePaths)]; newBoss.SetupEnemy(randomBossType, randomPath); HealthBar bossBar = newBoss.SetupBars(healthBarCanvas); Color bossBarColor = Color.magenta; bossBarColor.a = 0.8f; bossBar.ChangeBarColorTo(bossBarColor); bossBarColor.a = 0.95f; bossBar.ChangeBarEndColorTo(bossBarColor); newBoss.gameObject.name = "B" + numEnemyToSpawn + " - " + randomBossType.GetShortHand(); bosses.Add(newBoss); numEnemyToSpawn++; yield return(new WaitForSeconds(1.0f)); } numEnemyMax += (bossWave % maxEnemyIncreaseRate == 0) ? 1 : 0; bossesSpawning = false; }