Added spawn points + logic

This commit is contained in:
2025-08-02 09:11:23 +02:00
parent 630c54f7ff
commit 5bf23cf6d4
12 changed files with 1413 additions and 9 deletions

View File

@@ -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);
}
}