using System.Collections; using System.Collections.Generic; using UnityEngine; public class SpawnManager : MonoBehaviour { [SerializeField] private GameObject enemyPrefab; [SerializeField] private GameObject enemyContainer; private bool stopSpawning = false; void Start() { StartCoroutine(SpawnRoutine()); } IEnumerator SpawnRoutine() { while (!stopSpawning) { Vector3 posToSpawn = new Vector3(Random.Range(-8f, 8f), 7, 0); GameObject newEnemy = Instantiate(enemyPrefab, posToSpawn, Quaternion.identity); newEnemy.transform.SetParent(enemyContainer.transform); yield return new WaitForSeconds(5.0f); } } public void OnPlayerDeath() { stopSpawning = true; } }