using System.Collections; using UnityEngine; public class Spawner : MonoBehaviour { public GameObject enemyPrefab; public GameManager gameManager; void Start() { StartCoroutine(SpawnLoop()); } void Update() { } IEnumerator SpawnLoop() //Spawn random Enemy around Player every 3s { while (gameManager.gameRunning) { Vector3 randomSpot = Random.onUnitSphere * 3f; Instantiate(enemyPrefab, randomSpot, Quaternion.identity); yield return new WaitForSeconds(3f); } } }