47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
#nullable enable
|
|
using System.Collections;
|
|
using NaughtyAttributes;
|
|
using UnityEngine;
|
|
|
|
public class Arena : MonoBehaviour {
|
|
//TODO probably add initial direction too
|
|
[SerializeField] [Required]
|
|
Vector3[] spawners = null!;
|
|
[SerializeField] [Required]
|
|
ArenaStats stats = null!;
|
|
[SerializeField] [Required]
|
|
GameObject monsterPrefab = null!;
|
|
|
|
SafeZone safeZone = null!;
|
|
|
|
void Awake() => safeZone = GetComponentInChildren<SafeZone>();
|
|
|
|
void Start() => StartCoroutine(SpawnEnemies());
|
|
|
|
void SpawnEnemy(int spawnerIndex) {
|
|
var monster = Instantiate(monsterPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Monster>();
|
|
//TODO Replace hardcoded target with entity discovery
|
|
monster.SetTarget(FindObjectOfType<PlayerMovement>().transform);
|
|
}
|
|
|
|
IEnumerator SpawnEnemies() {
|
|
yield return new WaitForSeconds(stats.secondsBetweenSpawners);
|
|
|
|
int currentSpawner = 0;
|
|
|
|
//TODO Stop when pause/end game
|
|
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
|
|
} |