From 87189cd12426728987c8ecdae446c7403fb114fc Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sun, 3 Apr 2022 20:17:45 -0400 Subject: [PATCH] Only randomize title if high score > 0 --- Assets/Prefabs/MainMenu.prefab | 3 +++ Assets/Scripts/GameTimer.cs | 8 ++++---- Assets/Scripts/MainMenuManager.cs | 9 ++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Assets/Prefabs/MainMenu.prefab b/Assets/Prefabs/MainMenu.prefab index 6dd7320..3f07622 100644 --- a/Assets/Prefabs/MainMenu.prefab +++ b/Assets/Prefabs/MainMenu.prefab @@ -522,6 +522,9 @@ MonoBehaviour: - The Count's Last Feast - Vampire Arena - Out of Blood + - Bloody Colosseum + - Delay the Blood Rumblies + - Vampire Snack startButton: {fileID: 4394421821813469848} --- !u!223 &4394421820928219483 Canvas: diff --git a/Assets/Scripts/GameTimer.cs b/Assets/Scripts/GameTimer.cs index 75b1336..17ac651 100644 --- a/Assets/Scripts/GameTimer.cs +++ b/Assets/Scripts/GameTimer.cs @@ -25,12 +25,12 @@ public class GameTimer : MonoBehaviour { } bool showHighScore; - const string HighScoreKey = "High Score"; + public const string HIGH_SCORE_KEY = "High Score"; void Awake() { label = GetComponent(); timer = 0f; - highScore = PlayerPrefs.GetFloat(HighScoreKey); + highScore = PlayerPrefs.GetFloat(HIGH_SCORE_KEY); Stopped = true; } @@ -55,12 +55,12 @@ public class GameTimer : MonoBehaviour { if (timer <= highScore) return; - PlayerPrefs.SetFloat(HighScoreKey, timer); + PlayerPrefs.SetFloat(HIGH_SCORE_KEY, timer); highScore = timer; } public void ResetHighScore() { - PlayerPrefs.DeleteKey(HighScoreKey); + PlayerPrefs.DeleteKey(HIGH_SCORE_KEY); highScore = 0f; } } \ No newline at end of file diff --git a/Assets/Scripts/MainMenuManager.cs b/Assets/Scripts/MainMenuManager.cs index bf602a2..8aa5c8c 100644 --- a/Assets/Scripts/MainMenuManager.cs +++ b/Assets/Scripts/MainMenuManager.cs @@ -19,8 +19,15 @@ public class MainMenuManager : MonoBehaviour { void Awake() => mode = MenuMode.MainMenu; void Start() { - if (titleOptions.Length > 0) + if (titleOptions.Length == 0) { + Debug.LogWarning("No titles listed."); + return; + } + + if (PlayerPrefs.HasKey(GameTimer.HIGH_SCORE_KEY) && PlayerPrefs.GetFloat(GameTimer.HIGH_SCORE_KEY) > 0f) titleLable.text = titleOptions[Random.Range(0, titleOptions.Length)]; + else + titleLable.text = titleOptions[0]; } public void SetMenuMode(MenuMode mode) {