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.
59 lines
1.1 KiB
59 lines
1.1 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
public class ChoiceQuesition : MonoBehaviour
|
|
{
|
|
|
|
Toggle[] toggles;
|
|
|
|
[SerializeField]
|
|
private int answer;
|
|
|
|
private int currentAnswer;
|
|
|
|
|
|
public Button button;
|
|
|
|
public UnityEvent trueEvent;
|
|
public UnityEvent falseEvent;
|
|
|
|
private void Start()
|
|
{
|
|
toggles = GetComponentsInChildren<Toggle>();
|
|
for (int i = 0; i < toggles.Length; i++)
|
|
{
|
|
int index = i;
|
|
toggles[index].onValueChanged.AddListener((bool b) => {
|
|
if (toggles[index].isOn)
|
|
{
|
|
currentAnswer = index+1;
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
button.onClick.AddListener(CheckAnswer);
|
|
}
|
|
|
|
|
|
public void CheckAnswer()
|
|
{
|
|
if (currentAnswer == answer)
|
|
{
|
|
Debug.Log("回答正确");
|
|
trueEvent.Invoke();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("回答错误");
|
|
falseEvent.Invoke();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|