fgm24/Assets/Scripts/UI/WaveUI.cs

57 lines
1.3 KiB
C#
Raw Normal View History

2024-02-04 07:49:39 +01:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class WaveUI : MonoBehaviour
{
2024-02-04 07:59:28 +01:00
[SerializeField] private EnemySpawner spawner;
2024-02-04 07:49:39 +01:00
[SerializeField] private Slider slider;
[SerializeField] private TMP_Text waveText;
2024-02-04 07:59:28 +01:00
[SerializeField] private float waveTextDisplayTime = 3f;
private void Start()
{
2024-02-04 08:04:26 +01:00
waveText.color = new Color(1, 1, 1, 0);
2024-02-04 07:59:28 +01:00
}
int prevWave = 0;
private void Update()
{
float waveProgressTime = spawner.timer / spawner.WaveTime;
slider.value = waveProgressTime;
if (prevWave != spawner.Wave)
{
prevWave = spawner.Wave;
StartCoroutine(ShowWave());
}
}
IEnumerator ShowWave()
{
2024-02-04 08:23:13 +01:00
waveText.text = $"Wave: {spawner.Wave}";
2024-02-04 08:04:26 +01:00
Color color = new Color(1, 1, 1, 0);
2024-02-04 08:23:13 +01:00
while (color.a < 1)
2024-02-04 08:04:26 +01:00
{
color.a += 0.05f;
2024-02-04 08:23:13 +01:00
waveText.color = color;
yield return new WaitForSecondsRealtime(0.05f);
2024-02-04 08:04:26 +01:00
}
2024-02-04 07:59:28 +01:00
yield return new WaitForSecondsRealtime(waveTextDisplayTime);
2024-02-04 08:04:26 +01:00
color = new Color(1, 1, 1, 1);
2024-02-04 08:23:13 +01:00
while (color.a >= 0)
2024-02-04 08:04:26 +01:00
{
color.a -= 0.05f;
2024-02-04 08:23:13 +01:00
waveText.color = color;
yield return new WaitForSecondsRealtime(0.05f);
2024-02-04 08:04:26 +01:00
}
2024-02-04 07:59:28 +01:00
}
2024-02-04 07:49:39 +01:00
}