void AddEnemy() { int enemyCreated = 0; int numberOfEnemy = 0; int instanceOfEnemyType = 0; foreach (int j in numberOfEnemyType) { numberOfEnemy += j; } int maxEnemy = numberOfEnemy < size.x * size.z - 1 - entityOnMap ? numberOfEnemy : size.x * size.z - 1; for (int i = 0; i < mazeEnemiesPrefab.Length; ++i) { MazeEnemy ennemyPrefab; while (enemyCreated < maxEnemy && instanceOfEnemyType < numberOfEnemyType[i]) { ennemyPrefab = mazeEnemiesPrefab[i]; IntVector2 cellCoordinate = RandomCoordinates; if (entityMap[cellCoordinate.x, cellCoordinate.z] == 0) { MazeEnemy enemy = Instantiate(ennemyPrefab) as MazeEnemy; //passage.transform.localScale = passage.transform.localScale * scale; enemy.Initialize(cells[cellCoordinate.x, cellCoordinate.z], (MazeDirection)Random.Range(0, 3)); entityMap[cellCoordinate.x, cellCoordinate.z] = 1; enemyCreated++; instanceOfEnemyType++; } } instanceOfEnemyType = 0; } }
void AddEnemy() { int enemyCreated = 0; int maxEnemy = numberOfEnemy < size.x * size.z - 7 ? numberOfEnemy : size.x * size.z - 7; IntVector2 start = new IntVector2(0, 0); IntVector2 end = new IntVector2(size.x - 1, size.z - 1); entityMap[0, 0] = 1; entityMap[1, 0] = 1; entityMap[0, 1] = 1; entityMap[2, 0] = 1; entityMap[1, 1] = 1; entityMap[0, 2] = 1; entityMap[size.x - 1, size.z - 1] = 1; while (enemyCreated < maxEnemy) { IntVector2 cellCoordinate = RandomCoordinates; if (entityMap[cellCoordinate.x, cellCoordinate.z] == 0) { MazeEnemy passage = Instantiate(enemyPrefab) as MazeEnemy; passage.transform.localScale = passage.transform.localScale * scale; passage.Initialize(cells[cellCoordinate.x, cellCoordinate.z], (MazeDirection)Random.Range(0, 3)); entityMap[cellCoordinate.x, cellCoordinate.z] = 1; enemyCreated++; } } }
public IEnumerator Generate(LevelSettings levelSettings) { this.enemyPrefab = levelSettings.enemyType; this.numberOfEnemy = levelSettings.numberOfEnemy; this.roomSettings = levelSettings.roomSettings; this.size = levelSettings.size; yield return(Generate()); }