using System; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; namespace Level19 { public class Level19Manager : MonoBehaviour { public GameObject noAnswerTip; public GameObject passOverTip; public int currentAnswer; private int currentQuestionIndex = 1; public int AllQuestionIndex = 1; public Toggle[] toggles; private GameObject[] imgs; // Start is called before the first frame update void Start() { imgs = new GameObject[toggles.Length]; for (int i = 0; i < toggles.Length; i++) { imgs[i] =toggles[i].transform.Find("selectedImg").gameObject; } for (int i = 0; i < toggles.Length; i++) { int index = i; Toggle toggle = null; toggle = toggles[i]; toggle.onValueChanged.AddListener((bool b) => { if (toggle.isOn) { currentAnswer = index + 1; Debug.Log(currentAnswer); for (int j = 0; j < imgs.Length; j++) { imgs[j].SetActive(false); } imgs[index].SetActive(true); } else { currentAnswer = 0; for (int j = 0; j < imgs.Length; j++) { imgs[j].SetActive(false); } } }); } } public int GetCurrentQuestionIndex() { return currentQuestionIndex; } public void SubSinleAnswer() { if (currentAnswer == 0) { noAnswerTip.gameObject.SetActive(true); GameRoot.SubmitChoiceAnswer(19, 1, 0); } else { GameRoot.SubmitChoiceAnswer(19, 1, currentAnswer); Debug.Log("提交当前小题答案为" + currentAnswer); CheckQuesionIndex(); } } public void ReturnMenu() { GameRoot.ReturnMenu(); } public void CheckQuesionIndex() { if (currentQuestionIndex == AllQuestionIndex) { //提示完成答题,然后弹窗返回大厅 passOverTip.gameObject.SetActive(true); } else { //跳转下一题 currentQuestionIndex += 1; } } //记录关卡完成是否 public void CheckPassisOver() { GameRoot.SubmitPassState(19,true); } } }