From 472d5c8c6c033b74c9fc8a96432334e879f0fa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A1rk=C3=B6zi=20Gergely=20J=C3=A1nos?= <cycss7@inf.elte.hu> Date: Tue, 3 May 2022 23:54:33 +0200 Subject: [PATCH] don't display 'infinite time left' on UI --- Assets/Scripts/Presentation/UI/BattleUI.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Presentation/UI/BattleUI.cs b/Assets/Scripts/Presentation/UI/BattleUI.cs index ae3f291..dae25e4 100644 --- a/Assets/Scripts/Presentation/UI/BattleUI.cs +++ b/Assets/Scripts/Presentation/UI/BattleUI.cs @@ -141,9 +141,15 @@ public class BattleUI : MonoBehaviour { public void UpdateRemainingTime(float timeLeft) { if (!_active) return; - string text = $"{Mathf.Round(timeLeft * 100) / 100 + 0.001f}"; - text = text.Substring(0, text.Length - 1); // A small hack to keep the zeroes after the decimal point - RootElement.Q<Label>(TimeLeftText).text = $"Time remaining: {text}s"; + string text; + if (float.IsNaN(timeLeft) || float.IsInfinity(timeLeft)) { + text = "-"; + } else { + text = $"{Mathf.Round(timeLeft * 100) / 100 + 0.001f}"; + text = text.Substring(0, text.Length - 1); // A small hack to keep the zeroes after the decimal point + text += "s"; + } + RootElement.Q<Label>(TimeLeftText).text = $"Time remaining: {text}"; } /// <summary> -- GitLab