From 2129a89a6a25e73864a29efb867fc15503a96fbe Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sun, 4 Feb 2024 07:59:28 +0100 Subject: [PATCH] Finished waveUI --- Assets/Scenes/GameScene.unity | 15 ++++++++++ .../Controller/EnemySpawner/EnemySpawner.cs | 6 ++-- Assets/Scripts/UI/WaveUI.cs | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index f8d50bf..ba29552 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -2395,6 +2395,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1656765803503857110, guid: 48e0e53445d42474895d37a321c39d1c, type: 3} + propertyPath: spawner + value: + objectReference: {fileID: 5796191506433166634} - target: {fileID: 2404937059918327841, guid: 48e0e53445d42474895d37a321c39d1c, type: 3} propertyPath: m_AnchorMax.y value: 0 @@ -2645,6 +2649,17 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} +--- !u!114 &5796191506433166634 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3603265075407754381, guid: c53e6971c95afb1429cd82616a7b6737, type: 3} + m_PrefabInstance: {fileID: 5796191506433166633} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8a592fac78e06964b863b67047a446a1, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &7693964683212020007 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs index af02df7..7698809 100644 --- a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs +++ b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs @@ -18,16 +18,16 @@ public class EnemySpawner : MonoBehaviour // Inspector [SerializeField] private float difficultyIncreasePerWave = 1f; - [SerializeField] private float WaveTime = 20f; + [SerializeField] public float WaveTime = 20f; [SerializeField] private List enemyDifficulties; [SerializeField] private float SpawnRadius = 10; [SerializeField] private int NumEnemies = 6; [SerializeField] private GameObject[] players; [SerializeField] private float initialSpawnDelay = 5; - // Private + // local private bool nextWaveRequested = false; - private float timer = 0f; + public float timer = 0f; private Camera mainCam; private GameObject SpawnedEnenmyHolder; [SerializeField] private List enemyList; diff --git a/Assets/Scripts/UI/WaveUI.cs b/Assets/Scripts/UI/WaveUI.cs index d0b4bf7..8f5e2fb 100644 --- a/Assets/Scripts/UI/WaveUI.cs +++ b/Assets/Scripts/UI/WaveUI.cs @@ -6,6 +6,36 @@ using UnityEngine.UI; public class WaveUI : MonoBehaviour { + [SerializeField] private EnemySpawner spawner; [SerializeField] private Slider slider; [SerializeField] private TMP_Text waveText; + [SerializeField] private float waveTextDisplayTime = 3f; + + private void Start() + { + waveText.gameObject.SetActive(false); + } + + 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() + { + waveText.gameObject.SetActive(true); + waveText.text = $"Wave: {spawner.Wave}"; + + yield return new WaitForSecondsRealtime(waveTextDisplayTime); + + waveText.gameObject.SetActive(false); + } }