You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.1 KiB

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<string> InputResHandle;
public bool isRight;
//错误回调
public Action<string> ErrorHandle;
private void Awake()
{
input = this.transform.GetComponent<InputField>();
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;
}
}
}