From 7f1fc519ab938d636b895f8cb6eeb2c959641171 Mon Sep 17 00:00:00 2001 From: maikeljh <mjh191003@gmail.com> Date: Fri, 10 May 2024 02:54:13 +0700 Subject: [PATCH] [Fix] Timer --- Assets/Scenes/Level01.unity | 2 +- Assets/Scripts/Managers/LevelManager.cs | 5 ++++- .../Scripts/ShopKeeper/CollisionDetection.cs | 2 -- Assets/Scripts/ShopKeeper/TimerScript.cs | 18 +++++++++++++----- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Assets/Scenes/Level01.unity b/Assets/Scenes/Level01.unity index c01aff7..60da823 100644 --- a/Assets/Scenes/Level01.unity +++ b/Assets/Scenes/Level01.unity @@ -15655,7 +15655,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3854428197638761884, guid: 33c68c33f3888be4e957c37834df7765, type: 3} propertyPath: m_IsActive - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 4402895682815482158, guid: 33c68c33f3888be4e957c37834df7765, type: 3} propertyPath: m_Pivot.x diff --git a/Assets/Scripts/Managers/LevelManager.cs b/Assets/Scripts/Managers/LevelManager.cs index b521a2b..f7369b8 100644 --- a/Assets/Scripts/Managers/LevelManager.cs +++ b/Assets/Scripts/Managers/LevelManager.cs @@ -214,7 +214,10 @@ namespace Nightmare winQuest = false; isShopKeeper = true; if (shopKeeper) shopKeeper.SetActive(true); - if (timerCanvas) timerCanvas.SetActive(true); + if (timerCanvas) + { + timerCanvas.SetActive(true); + } if (saveHouse) saveHouse.enabled = true; // Disable skipQuest diff --git a/Assets/Scripts/ShopKeeper/CollisionDetection.cs b/Assets/Scripts/ShopKeeper/CollisionDetection.cs index 185ddad..c0c1e99 100644 --- a/Assets/Scripts/ShopKeeper/CollisionDetection.cs +++ b/Assets/Scripts/ShopKeeper/CollisionDetection.cs @@ -60,7 +60,6 @@ public class CollisionDetection : MonoBehaviour shopCanvas.gameObject.SetActive(false); shopInstructionCanvas.gameObject.SetActive(false); timerColor.a = 1f; - timerCanvasTimerUI.color = timerColor; } } @@ -69,7 +68,6 @@ public class CollisionDetection : MonoBehaviour shopCanvas.gameObject.SetActive(false); shopInstructionCanvas.gameObject.SetActive(true); timerColor.a = 1f; - timerCanvasTimerUI.color = timerColor; } } diff --git a/Assets/Scripts/ShopKeeper/TimerScript.cs b/Assets/Scripts/ShopKeeper/TimerScript.cs index c6d0f69..c3b6b2a 100644 --- a/Assets/Scripts/ShopKeeper/TimerScript.cs +++ b/Assets/Scripts/ShopKeeper/TimerScript.cs @@ -9,7 +9,8 @@ public class TimerScript : MonoBehaviour, IDataPersistence public Canvas shopCanvas; public Canvas shopInstructionCanvas; public Canvas timerCanvas; - private float timer = 60f; + public float timer = 60f; + public bool finishLoad = false; void Start() { @@ -24,11 +25,13 @@ public class TimerScript : MonoBehaviour, IDataPersistence void OnDisable() { StopTimerCountDown(); + this.timer = 60f; } public void LoadData(GameData data) { this.timer = data.shopKeeperTime; + finishLoad = true; } public void SaveData(ref GameData data) @@ -49,14 +52,19 @@ public class TimerScript : MonoBehaviour, IDataPersistence shopCanvas.gameObject.SetActive(false); shopInstructionCanvas.gameObject.SetActive(false); StopTimerCountDown(); - ResetTimer(); } private void UpdateTimerDisplay() { - int minutes = Mathf.FloorToInt(timer / 60); - int seconds = Mathf.FloorToInt(timer % 60); - timerUI.text = "Shop close in: " + string.Format("{0:00}:{1:00}", minutes, seconds); + if (finishLoad) + { + int minutes = Mathf.FloorToInt(timer / 60); + int seconds = Mathf.FloorToInt(timer % 60); + timerUI.text = "Shop close in: " + string.Format("{0:00}:{1:00}", minutes, seconds); + } else + { + timerUI.text = ""; + } } private void StartTimerCountDown() -- GitLab