using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Threading.Tasks; public class UsernameValidateSubmit : MonoBehaviour { private void Start() { GetComponent().onValidateInput += delegate (string s, int i, char c) { return char.IsLetter(c) ? char.ToUpper(c) : '\0'; }; GetComponent().Select(); } public void ValidateInput() { if (Input.GetKeyDown(KeyCode.Return) && GetComponent().text.Length == 3) { 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"); } } }