From cd0d00af48c8bbd9ee6cc287dad29651962f6472 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sun, 21 Apr 2024 06:13:36 +0200 Subject: [PATCH] Added start, autoplay, Next buttons support --- Assets/Scripts/Manager/EnemySpawnManager.cs | 37 ++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Manager/EnemySpawnManager.cs b/Assets/Scripts/Manager/EnemySpawnManager.cs index 3fdde05..905f339 100644 --- a/Assets/Scripts/Manager/EnemySpawnManager.cs +++ b/Assets/Scripts/Manager/EnemySpawnManager.cs @@ -2,9 +2,13 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.UI; public class EnemySpawnManager : MonoBehaviour { + public bool HasStarted = false; + public bool IsAutoPlaying = false; + private float time = 0f; [SerializeField] private LevelDefinition levelDefinition; [SerializeField] private EnemyCollection enemyCollection; @@ -12,11 +16,41 @@ public class EnemySpawnManager : MonoBehaviour [SerializeField] private WaypointPath groundPath; [SerializeField] private WaypointPath skyPath; + [Header("Buttons")] + + [SerializeField] private Button StartButton; + [SerializeField] private Button NextButton; + [SerializeField] private Button AutoPlayButton; + private Queue waveQueue; private void Awake() { waveQueue = new Queue(levelDefinition.Waves); + + if (StartButton != null) + StartButton.onClick.AddListener(OnStartButtonClicked); + if (NextButton != null) + NextButton.onClick.AddListener(OnNextButtonClicked); + if (AutoPlayButton != null) + AutoPlayButton.onClick.AddListener(ToggleAutoPlayClicked); + } + + public void OnStartButtonClicked() + { + HasStarted = true; + PopWave(); + } + + public void OnNextButtonClicked() + { + time = waveQueue.Peek().spawnTime; + PopWave(); + } + + public void ToggleAutoPlayClicked() + { + IsAutoPlaying = !IsAutoPlaying; } void Update() @@ -26,7 +60,8 @@ public class EnemySpawnManager : MonoBehaviour return; } - time += Time.deltaTime; + if (HasStarted && IsAutoPlaying) + time += Time.deltaTime; if (waveQueue.Peek().spawnTime < time) {