#nullable enable using System.Collections; using NaughtyAttributes; using UnityEngine; public class Arena : MonoBehaviour { [SerializeField] [Required] GameFlowManager gameFlowManager = null!; //TODO probably add initial direction too //TODO Add some kind of "MinLength(1)" attribute [SerializeField] Vector3[] spawners = null!; [SerializeField] [Required] ArenaStats stats = null!; [SerializeField] [Required] GameObject monsterPrefab = null!; SafeZone safeZone = null!; void Awake() => safeZone = GetComponentInChildren(); void Start() => StartCoroutine(SpawnEnemies()); void SpawnEnemy(int spawnerIndex) { if (gameFlowManager.Paused) return; var monster = Instantiate(monsterPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent(); //TODO Replace hardcoded target with entity discovery monster.SetTarget(FindObjectOfType().transform); } IEnumerator SpawnEnemies() { yield return new WaitForSeconds(stats.secondsBetweenSpawners); int currentSpawner = 0; while (true) { SpawnEnemy(currentSpawner); currentSpawner = Random.Range(0, spawners.Length); yield return new WaitForSeconds(stats.secondsBetweenSpawners); } } #if UNITY_EDITOR void OnDrawGizmosSelected() { Gizmos.color = Color.blue; foreach (Vector3 spawner in spawners) Gizmos.DrawWireCube(spawner, Vector3.one); } #endif }