Added enemy, fixed spawn logic

This commit is contained in:
2025-08-02 16:04:33 +02:00
parent 4bf2804650
commit 3efe2070c4
16 changed files with 346 additions and 30 deletions

View File

@@ -25,6 +25,7 @@ public class RoomHandler : MonoBehaviour
[Header("Spawn Points")]
[SerializeField] private List<GameObject> spawnPoints;
[SerializeField] private GameObject test;
[SerializeField] private bool allowSpawn = false;
private readonly Dictionary<Side, DoorAnimation> doors = new();
@@ -64,23 +65,32 @@ public class RoomHandler : MonoBehaviour
public void SpawnEnemies(List<GameObject> enemyPrefabs)
{
int i = 0;
List<GameObject> enemyPrefabsLocal = new List<GameObject>(enemyPrefabs);
while (enemyPrefabsLocal.Count > 0)
if (!allowSpawn)
{
// Spawns enemy and removes it from the list
GameObject enemyPrefab = enemyPrefabsLocal[0];
enemyPrefabsLocal.RemoveAt(0);
// Select a spawn point with round-robin
Debug.Log("Ammount of spawn points: " + spawnPoints.Count);
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++;
Debug.LogWarning("Enemy spawning is not allowed in this room.");
return;
}
else
{
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
Debug.Log("Ammount of spawn points: " + spawnPoints.Count);
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()
{