From 70467b76a1d375f4cef6ae0e07e55e8bce3561c1 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 30 Sep 2022 22:45:39 -0400 Subject: [PATCH] Fixed #393 --- .../Utility/DebugUtilities/DebugRaycaster.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs index 16f502e8..6f4e23fa 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugRaycaster.cs @@ -19,24 +19,31 @@ namespace NewHorizons.Utility.DebugUtilities private ScreenPrompt _raycastPrompt; - private void Awake() + private void Start() { _rb = this.GetRequiredComponent(); - _raycastPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_RAYCAST", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.P)); - - Locator.GetPromptManager().AddScreenPrompt(_raycastPrompt, PromptPosition.UpperRight, false); + if (_raycastPrompt == null) + { + _raycastPrompt = new ScreenPrompt(TranslationHandler.GetTranslation("DEBUG_RAYCAST", TranslationHandler.TextType.UI) + " ", ImageUtilities.GetButtonSprite(KeyCode.P)); + Locator.GetPromptManager().AddScreenPrompt(_raycastPrompt, PromptPosition.UpperRight, false); + } } private void OnDestroy() { - Locator.GetPromptManager()?.RemoveScreenPrompt(_raycastPrompt, PromptPosition.UpperRight); + if (_raycastPrompt != null) + { + Locator.GetPromptManager()?.RemoveScreenPrompt(_raycastPrompt, PromptPosition.UpperRight); + } } private void Update() { UpdatePromptVisibility(); + if (!Main.Debug) return; + if (Keyboard.current == null) return; if (Keyboard.current[Key.P].wasReleasedThisFrame) @@ -48,7 +55,10 @@ namespace NewHorizons.Utility.DebugUtilities public void UpdatePromptVisibility() { - _raycastPrompt.SetVisibility(!OWTime.IsPaused() && Main.Debug); + if (_raycastPrompt != null) + { + _raycastPrompt.SetVisibility(!OWTime.IsPaused() && Main.Debug); + } }