Added Visual Response on Invalid Input

This commit is contained in:
Philip W 2021-11-14 14:33:44 +00:00
parent 4cd2a24436
commit 1c097ed28a
2 changed files with 51 additions and 1 deletions

View File

@ -5053,7 +5053,7 @@ MonoBehaviour:
m_Calls: m_Calls:
- m_Target: {fileID: 839555747} - m_Target: {fileID: 839555747}
m_TargetAssemblyTypeName: UsernameValidateSubmit, Assembly-CSharp m_TargetAssemblyTypeName: UsernameValidateSubmit, Assembly-CSharp
m_MethodName: ValidateInput m_MethodName: buttonValidateInput
m_Mode: 1 m_Mode: 1
m_Arguments: m_Arguments:
m_ObjectArgument: {fileID: 0} m_ObjectArgument: {fileID: 0}

View File

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using System.Threading.Tasks;
public class UsernameValidateSubmit : MonoBehaviour public class UsernameValidateSubmit : MonoBehaviour
{ {
private void Start() private void Start()
@ -15,5 +16,54 @@ public class UsernameValidateSubmit : MonoBehaviour
{ {
GameObject.Find("GameOverPanel").GetComponent<LeaderboardHandle>().SubmitScores(); GameObject.Find("GameOverPanel").GetComponent<LeaderboardHandle>().SubmitScores();
} }
else if (Input.GetKeyDown(KeyCode.Return))
{
FlashRed();
}
}
public void buttonValidateInput()
{
if (GetComponent<InputField>().text.Length == 3)
{
GameObject.Find("GameOverPanel").GetComponent<LeaderboardHandle>().SubmitScores();
}
else
{
FlashRed();
}
}
public async void FlashRed()
{
try
{
if (GetComponent<InputField>().text != "")
{
Color defaultColor = GetComponent<InputField>().textComponent.color;
GetComponent<InputField>().textComponent.color = Color.red;
await Task.Delay(100);
GetComponent<InputField>().textComponent.color = defaultColor;
await Task.Delay(100);
GetComponent<InputField>().textComponent.color = Color.red;
await Task.Delay(100);
GetComponent<InputField>().textComponent.color = defaultColor;
}
else
{
Color defaultColor = GetComponent<InputField>().placeholder.color;
GetComponent<InputField>().placeholder.color = Color.red;
await Task.Delay(100);
GetComponent<InputField>().placeholder.color = defaultColor;
await Task.Delay(100);
GetComponent<InputField>().placeholder.color = Color.red;
await Task.Delay(100);
GetComponent<InputField>().placeholder.color = defaultColor;
}
}
catch (MissingReferenceException)
{
Debug.Log("Missing Reference: Ignoring Due to Async Winddown");
}
} }
} }