Added spawn points + logic
This commit is contained in:
@@ -21,6 +21,11 @@ public class RoomHandler : MonoBehaviour
|
||||
West
|
||||
}
|
||||
|
||||
// Room Spawn Points
|
||||
[Header("Spawn Points")]
|
||||
[SerializeField] private List<GameObject> spawnPoints;
|
||||
[SerializeField] private GameObject test;
|
||||
|
||||
private readonly Dictionary<Side, DoorAnimation> doors = new();
|
||||
|
||||
public void RegisterDoor(Side dir, DoorAnimation doorAnim) => doors[dir] = doorAnim;
|
||||
@@ -56,4 +61,35 @@ public class RoomHandler : MonoBehaviour
|
||||
Debug.Log("Door " + dir + " is now " + (open ? "open" : "closed"));
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnEnemies(List<GameObject> enemyPrefabs)
|
||||
{
|
||||
int i = 0;
|
||||
List<GameObject> enemyPrefabsLocal = new List<GameObject>(enemyPrefabs);
|
||||
while (enemyPrefabsLocal.Count > 0)
|
||||
{
|
||||
// Spawns enemy and removes it from the list
|
||||
GameObject enemyPrefab = enemyPrefabsLocal[0];
|
||||
enemyPrefabsLocal.RemoveAt(0);
|
||||
|
||||
// Select a spawn point with round-robin
|
||||
GameObject spawnPoint = spawnPoints[i % spawnPoints.Count];
|
||||
|
||||
Instantiate(enemyPrefab, spawnPoint.transform.position + new Vector3(0, 1, 0), Quaternion.identity);
|
||||
Debug.Log("Spawned enemy: " + enemyPrefab.name + " at " + spawnPoint.transform.position);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
int enemyCount = Random.Range(1, 4);
|
||||
List<GameObject> enemyPrefabs = new List<GameObject>();
|
||||
for (int i = 0; i < enemyCount; i++)
|
||||
{
|
||||
enemyPrefabs.Add(test);
|
||||
}
|
||||
|
||||
SpawnEnemies(enemyPrefabs);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user