using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class IIIInputChector : MonoBehaviour { [Header("正确答案")] public string right_ans; private InputField input; public Action InputResHandle; public bool isRight; //错误回调 public Action ErrorHandle; private void Awake() { input = this.transform.GetComponent(); input.onValueChanged.AddListener(ChectInput); } void ChectInput(string val) { if (string.IsNullOrEmpty(val)) return; InputResHandle?.Invoke(val); int right = -1; if (!string.IsNullOrEmpty(right_ans)) right = int.Parse(right_ans); int val_int = int.Parse(val); if (string.IsNullOrEmpty(right_ans) || right == -1)//不需要判断 { isRight = true; } else if(val_int == right)//正确判断 { isRight = true; }else { isRight = false; } } }