using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UIDisplay : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI waveText;
[SerializeField] private TextMeshProUGUI timeText;
[SerializeField] private TextMeshProUGUI scoreText;
[SerializeField] private Slider healthSlider;
private void Start() {
scoreText.text = "000000000";
healthSlider.value = 1;
}
private void Update() {
timeText.text = "TIME: " + Mathf.Round(Time.timeSinceLevelLoad).ToString("0000");
}
public void UpdateScore(int value) {
scoreText.text = value.ToString("000000000");
}
public void UpdateHealth(int maxHP, int currentHP) {
healthSlider.value = (float)currentHP / maxHP;
}
public void UpdateWave(int waveCount) {
waveText.text = "WAVE: " + waveCount.ToString("0000");
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] private List<WaveConfigurationSO> waveConfigurationSOs;
[SerializeField] private float timeBetweenWaves = 0f;
[SerializeField] private bool isLooping = true;
private WaveConfigurationSO currentWave;
private int waveCount = 0;
private UIDisplay uiDisplay;
private void Awake() {
uiDisplay = FindObjectOfType<UIDisplay>();
}
private void Start() {
StartCoroutine(SpawnEnemyWaves());
}
public WaveConfigurationSO GetCurrentWaveSO() {
return currentWave;
}
private IEnumerator SpawnEnemyWaves() {
do {
foreach (WaveConfigurationSO waveConfigurationSO in waveConfigurationSOs) {
currentWave = waveConfigurationSO;
waveCount++;
uiDisplay.UpdateWave(waveCount);
for (int i = 0; i < currentWave.GetEnemyCount(); i++) {
Instantiate(currentWave.GetEnemyPrefab(i),
currentWave.GetStartingWaypoint().position,
Quaternion.Euler(0, 0, 180),
transform);
yield return new WaitForSeconds(currentWave.GetRandomSpawnTime());
}
yield return new WaitForSeconds(timeBetweenWaves);
}
} while (isLooping);
}
}