Jason Durand 01 271bd1d93f Merge remote-tracking branch 'origin/dev' into jason
# Conflicts:
#	Assets/Scripts/VampireEntity.cs
2022-04-02 19:18:50 -04:00

68 lines
1.7 KiB
C#

#nullable enable
using System;
using System.Collections;
using NaughtyAttributes;
using UnityEngine;
using Random = UnityEngine.Random;
public class Arena : MonoBehaviour {
[Serializable]
struct GladiatorEntrance {
public Vector2 position;
public Vector2 direction;
}
[SerializeField] [Required]
GameFlowManager gameFlowManager = null!;
//TODO probably add initial direction too
//TODO Add some kind of "MinLength(1)" attribute
[SerializeField]
GladiatorEntrance[] 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.CanDoAction)
return;
var entity = Instantiate(entityPrefab, spawners[spawnerIndex].position, Quaternion.identity).GetComponent<Entity>();
entity.direction = spawners[spawnerIndex].direction;
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 (GladiatorEntrance entrance in spawners) {
Gizmos.DrawWireCube(entrance.position, Vector3.one);
Gizmos.DrawLine(entrance.position, entrance.position + entrance.direction);
}
}
#endif
}