private void SpawnEnemy(int num) { for (int i = 0; i < num; i++) { GameObject e = Instantiate(enemy); e.SetActive(true); e.transform.SetParent(playArea.transform); Enemy.TYPE type = (Enemy.TYPE)Random.Range(0, 3); e.GetComponent <Enemy>().SetEnemy(new Vector2(Random.Range(0, mapWidth), Random.Range(0, mapHeight)), type); } }
public List <Enemy> spawnMonsters() { if (position.x == 1 && position.y == 1) { return(new List <Enemy>()); } int maxEnemies = 2 + size.x * size.y / 15; int number = UnityEngine.Random.Range(0, maxEnemies); Debug.Log("Rolled " + number + " enemies (out of " + maxEnemies + " possible) for sector " + position + " (size " + size.x + " x " + size.y + " = " + size.x * size.y + ")"); if (size.x < 3 || size.y < 3) { return(new List <Enemy>()); } if (number >= (size.x - 1) * (size.y - 1)) { number = (size.x - 1) * (size.y - 1) - 1; } List <Enemy> enemyList = new List <Enemy>(); List <Vector2Int> filledSpaces = new List <Vector2Int>(); for (int i = 0; i < number; i++) { Vector2Int roomLocation = new Vector2Int(UnityEngine.Random.Range(0, size.x), UnityEngine.Random.Range(0, size.y)); while (filledSpaces.Contains(roomLocation)) { roomLocation = new Vector2Int(UnityEngine.Random.Range(0, size.x), UnityEngine.Random.Range(0, size.y)); } filledSpaces.Add(roomLocation); Vector2Int spawnLocation = sectorToDungeonCoordinates(roomLocation); Enemy.TYPE type = Enemy.TYPE.SLIME; if (UnityEngine.Random.value > 0.7f) { type = Enemy.TYPE.SKELLINGTON; } Enemy e = Game.getEnemyHandler().spawnEnemy(type, spawnLocation); enemies.Add(e); } return(enemies); }
public Enemy spawnEnemy(Enemy.TYPE type, Vector2Int location) { //GameObject enemyGO = GameObject.Instantiate(slime, new Vector3Int(location.x, location.y, -3), Quaternion.identity); Enemy enemy; switch (type) { case Enemy.TYPE.SLIME: enemy = new Slime(location); break; case Enemy.TYPE.SKELLINGTON: enemy = new Skellington(location); break; default: enemy = new Slime(location); break; } enemies.Add(enemy); return(enemy); }