using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.UI; public class ControllerQuestions : MonoBehaviour { public static bool finishedGame = false; public static bool ended = false; Questions questions; Text btn1, btn2, btn3, btn4; GameObject obj1, obj2, obj3, obj4; Text txtEnunciado; int index = 0; Animator anime; int nbrQuestions; Animator winn; // Start is called before the first frame update void Awake() { ended = false; index = 0; questions = GetComponent(); anime = GetComponent(); winn = GameObject.Find("YouWinPanel").GetComponent(); nbrQuestions = questions.questions.Count; txtEnunciado = GameObject.Find("Enunciado").GetComponent(); if (!questions.hasTitle) { GameObject obj = txtEnunciado.gameObject; obj.SetActive(false); } btn1 = GameObject.Find("q1").GetComponent(); btn2 = GameObject.Find("q2").GetComponent(); btn3 = GameObject.Find("q3").GetComponent(); btn4 = GameObject.Find("q4").GetComponent(); obj1 = GameObject.Find("Q1"); obj2 = GameObject.Find("Q2"); obj3 = GameObject.Find("Q3"); obj4 = GameObject.Find("Q4"); ChangeQuestion(); finishedGame = false; GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.ended = false; jooj.finishedGame = false; jooj.failedGame = false; } void ChangeQuestion() { changeButtonState(false); index++; if (index > nbrQuestions) { winn.SetBool("done", true); ended = true; finishedGame = true; win(); } else { anime.SetInteger("index", index); } } void changeButtonState(bool state) { obj1.SetActive(state); obj2.SetActive(state); obj3.SetActive(state); obj4.SetActive(state); } public void SetQuestion() { int i = index - 1; changeButtonState(true); btn1.text = questions.questions[i].question1; btn2.text = questions.questions[i].question2; btn3.text = questions.questions[i].question3; btn4.text = questions.questions[i].question4; if (questions.hasTitle) { txtEnunciado.text = questions.questions[i].enunciado; } } void win() { GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.finishedGame = true; } void Lost() { GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.failedGame = true; } public void Answer(int i) { if (!ended) { if (i == questions.questions[index - 1].rightAnswer) { ChangeQuestion(); } else { switch (i) { case 1: obj1.SetActive(false); break; case 2: obj2.SetActive(false); break; case 3: obj3.SetActive(false); break; case 4: obj4.SetActive(false); break; } } } } }