using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MyInput : MonoBehaviour { public InputField inputField; public List key; public bool boolOpen; public GameObject one, two; public int IntName; public List ObjList; public GameObject mistakeTetx; //错误显示文本 // Update is called once per frame void Update() { if (!boolOpen) { if (Input.GetKeyDown(KeyCode.Return) && inputField.text.Contains(key[0]) && !inputField.text.Contains(key[1])) { switch (IntName) { case 0: mistakeTetx.SetActive(false); one.SetActive(true); boolOpen = true; Invoke("yc", 2); break; case 1: mistakeTetx.SetActive(false); StartCoroutine(display()); boolOpen = true; Invoke("yc", 5); break; } } if (Input.GetKeyDown(KeyCode.Return) && inputField.text.Contains(key[1])) { switch (IntName) { case 0: mistakeTetx.SetActive(false); two.SetActive(true); boolOpen = true; Invoke("yc", 2); break; case 1: mistakeTetx.SetActive(false); StartCoroutine(display()); boolOpen = true; Invoke("yc", 5); break; } } if(Input.GetKeyDown(KeyCode.Return) && !inputField.text.Contains(key[1])&& !inputField.text.Contains(key[0])) { mistakeTetx.SetActive(true); } } } IEnumerator display() { for (int i = 0; i < ObjList.Count; i++) { yield return new WaitForSeconds(0.5f); ObjList[i].SetActive(true); } } /// /// 延迟执行 /// public void yc() { GameManager.Instance.UpdateQuestionIndex(); this.gameObject.SetActive(false); } }