using UnityEngine; using System.Collections; using System.Collections.Generic; public class MonsterGroupManager : MonoBehaviour { public MonsterData monsterType; public int numberOfMonsters = 5; public float respawnTime = 300f; // 5 min public Vector3 spawnCenter; public float spacing = 1.5f; private List spawnedMonsters = new(); private bool isRespawning = false; void Start() { SpawnMonsters(); } public void SpawnMonsters() { for (int i = 0; i < numberOfMonsters; i++) { Vector3 spawnPos = spawnCenter + new Vector3((i % 3) * spacing, 0, -(i / 3) * spacing); GameObject m = Instantiate(monsterType.prefab, spawnPos, Quaternion.identity); MonsterController ctrl = m.GetComponent(); ctrl.data = monsterType; ctrl.Setup(this); spawnedMonsters.Add(m); } } public void OnMonsterDefeated(GameObject monster) { spawnedMonsters.Remove(monster); Destroy(monster); if (!isRespawning && spawnedMonsters.Count == 0) StartCoroutine(RespawnDelay()); } IEnumerator RespawnDelay() { isRespawning = true; yield return new WaitForSeconds(respawnTime); SpawnMonsters(); isRespawning = false; } }