From 1c097ed28a9d4ee0a12f06a2b4fdbc3779717c6a Mon Sep 17 00:00:00 2001 From: Philip White Date: Sun, 14 Nov 2021 14:33:44 +0000 Subject: [PATCH] Added Visual Response on Invalid Input --- .../Assets/Examples/Defender/Defender.unity | 2 +- .../Scripts/Menu/UsernameValidateSubmit.cs | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Unity-Files/Assets/Examples/Defender/Defender.unity b/Unity-Files/Assets/Examples/Defender/Defender.unity index 18a5c7d..420208a 100644 --- a/Unity-Files/Assets/Examples/Defender/Defender.unity +++ b/Unity-Files/Assets/Examples/Defender/Defender.unity @@ -5053,7 +5053,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 839555747} m_TargetAssemblyTypeName: UsernameValidateSubmit, Assembly-CSharp - m_MethodName: ValidateInput + m_MethodName: buttonValidateInput m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Unity-Files/Assets/Scripts/Menu/UsernameValidateSubmit.cs b/Unity-Files/Assets/Scripts/Menu/UsernameValidateSubmit.cs index 33ea6ba..f48f202 100644 --- a/Unity-Files/Assets/Scripts/Menu/UsernameValidateSubmit.cs +++ b/Unity-Files/Assets/Scripts/Menu/UsernameValidateSubmit.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using System.Threading.Tasks; public class UsernameValidateSubmit : MonoBehaviour { private void Start() @@ -15,5 +16,54 @@ public class UsernameValidateSubmit : MonoBehaviour { GameObject.Find("GameOverPanel").GetComponent().SubmitScores(); } + else if (Input.GetKeyDown(KeyCode.Return)) + { + FlashRed(); + } + } + + public void buttonValidateInput() + { + if (GetComponent().text.Length == 3) + { + GameObject.Find("GameOverPanel").GetComponent().SubmitScores(); + } + else + { + FlashRed(); + } + } + + public async void FlashRed() + { + try + { + if (GetComponent().text != "") + { + Color defaultColor = GetComponent().textComponent.color; + GetComponent().textComponent.color = Color.red; + await Task.Delay(100); + GetComponent().textComponent.color = defaultColor; + await Task.Delay(100); + GetComponent().textComponent.color = Color.red; + await Task.Delay(100); + GetComponent().textComponent.color = defaultColor; + } + else + { + Color defaultColor = GetComponent().placeholder.color; + GetComponent().placeholder.color = Color.red; + await Task.Delay(100); + GetComponent().placeholder.color = defaultColor; + await Task.Delay(100); + GetComponent().placeholder.color = Color.red; + await Task.Delay(100); + GetComponent().placeholder.color = defaultColor; + } + } + catch (MissingReferenceException) + { + Debug.Log("Missing Reference: Ignoring Due to Async Winddown"); + } } }