/// <summary> /// Spawns enemies at all EnemySpawnPoints and deletes those /// </summary> private void SpawnEnemies() { GameObject[] enemySpawnPoints = GameObject.FindGameObjectsWithTag(DungeonGenerator.EnemySpawnPointTag); int enemyLeaderIndex = 0; foreach (GameObject enemySpawnPoint in enemySpawnPoints) { int enemyCount = Random.Range(this.enemyCount.x, this.enemyCount.y + 1); if (enemyCount > 0) { EnemyDriver leaderEnemy = null, followEnemy = null; for (int index = 0; index < enemyCount; index++) { EnemyDriver enemy = this.SpawnEnemy( enemySpawnPoint.transform.position, ref leaderEnemy, ref followEnemy); enemy.name = string.Format("Enemy #{0}-{1}", enemyLeaderIndex, index); } } MonoBehaviour.Destroy(enemySpawnPoint); ++enemyLeaderIndex; } }
/// <summary> /// Spawns a boss at all a Boss spawn point /// </summary> private void SpawnBoss() { GameObject bossSpawnPoint = GameObject.FindGameObjectWithTag(DungeonGenerator.BossSpawnPointTag); EnemyDriver boss = MonoBehaviour.Instantiate(this.bossPrefabs.GetRandomItem(), this.entityParent); boss.transform.position = bossSpawnPoint.transform.position; boss.battleDriver.Level = Mathf.FloorToInt(this.EntityLevel * DungeonGenerator.BossLevelMultiplier); ActivityHandler.Add(boss.gameObject); MonoBehaviour.Destroy(bossSpawnPoint); }
/// <summary> /// Spawns and returns an enemy /// </summary> /// <param name="position">The position to spawn at</param> /// <param name="leaderEnemy">The leader</param> /// <param name="followEnemy">The enemy to follow</param> /// <returns>The newly spawned enemy</returns> private EnemyDriver SpawnEnemy(Vector3 position, ref EnemyDriver leaderEnemy, ref EnemyDriver followEnemy) { EnemyDriver newEnemy = MonoBehaviour.Instantiate(this.enemyPrefabs.GetRandomItem(), this.entityParent); newEnemy.transform.position = position + this.GetRandomEntityOffset(); newEnemy.battleDriver.Level = this.EntityLevel; newEnemy.SetLeaderAndFollowing(leaderEnemy, followEnemy); if (leaderEnemy == null) { leaderEnemy = newEnemy; } followEnemy = newEnemy; ActivityHandler.Add(newEnemy.gameObject); return(newEnemy); }