using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.UI; public class ControlQuestionsA : MonoBehaviour { public static bool finishedGame = false; public static bool ended = false; int index = 0; private Text Op1, Op2, Op3; public Image imgOp_01, imgOp_02, imgOp_03; private Text Enunciado; private int Etapa = 0; private bool Ended = false; public AudioSource audio; public AudioClip correct, wrong; public List Questoes; private Animator WinPanel, LostPanel, MainAnime; [System.Serializable] public class Opcao { public string Questao1, Questao2, Questao3, Enunciado, Certo; } // Start is called before the first frame update void Start() { int index = 0; ended = false; finishedGame = false; GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.ended = false; jooj.finishedGame = false; jooj.failedGame = false; Op1 = GameObject.Find("TextOp1").GetComponent(); Op2 = GameObject.Find("TextOp2").GetComponent(); Op3 = GameObject.Find("TextOp3").GetComponent(); Enunciado = GameObject.Find("Enunciado").GetComponent(); MainAnime = GameObject.Find("MainAnimation").GetComponent(); Op1.text = Questoes[Etapa].Questao1; Op2.text = Questoes[Etapa].Questao2; Op3.text = Questoes[Etapa].Questao3; Enunciado.text = Questoes[Etapa].Enunciado; } public void VerificaResposta(Text Answer) { if (!Ended) { Text txtAnswer = Answer.gameObject.GetComponentInChildren(); if (txtAnswer.text == Questoes[Etapa].Certo) { if ((Etapa + 1) == Questoes.Count) { CorrectSound(); StartCoroutine(endgame(2.5f)); } else { CorrectSound(); Etapa++; Op1.text = Questoes[Etapa].Questao1; Op1.color = Color.black; imgOp_01.color = Color.white; Op2.text = Questoes[Etapa].Questao2; Op2.color = Color.black; imgOp_02.color = Color.white; Op3.text = Questoes[Etapa].Questao3; Op3.color = Color.black; imgOp_03.color = Color.white; Enunciado.text = Questoes[Etapa].Enunciado; MainAnime.SetInteger("Etapa", MainAnime.GetInteger("Etapa") + 1); } } else { WrongSound(); Answer.color = new Color(0.9245283f, 0.2660199f, 0.2660199f, 1); txtAnswer.text = "Wrong"; txtAnswer.color = Color.white; } } } void win() { GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.finishedGame = true; } void Lost() { GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.failedGame = true; } IEnumerator endgame(float wait) { yield return new WaitForSeconds(wait); win(); } void CorrectSound() { audio.clip = correct; audio.Play(); } void WrongSound() { audio.clip = wrong; audio.Play(); } }