2022-04-02 17:17:47 -04:00

57 lines
1.4 KiB
C#

#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 entityPrefab = null!;
SafeZone safeZone = null!;
void Awake() => safeZone = GetComponentInChildren<SafeZone>();
void Start() => StartCoroutine(SpawnEnemies());
void SpawnEnemy(int spawnerIndex) {
if (gameFlowManager.Paused)
return;
var entity = Instantiate(entityPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Entity>();
entity.gameFlowManager = (gameFlowManager);
}
IEnumerator SpawnEnemies() {
yield return new WaitForSeconds(stats.initWaitToSpawn);
int currentSpawner = 0;
int amountSpawned = 0;
while(true){
while (amountSpawned < stats.waveSize) {
currentSpawner = Random.Range(0, spawners.Length);
SpawnEnemy(currentSpawner);
amountSpawned++;
}
yield return new WaitForSeconds(stats.secondsBetweenSpawners);
amountSpawned = 0;
}
}
#if UNITY_EDITOR
void OnDrawGizmosSelected() {
Gizmos.color = Color.blue;
foreach (Vector3 spawner in spawners)
Gizmos.DrawWireCube(spawner, Vector3.one);
}
#endif
}