using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CtrlSports7 : MonoBehaviour { private int Etapa = 0; private Text op1, op2, op3; public AudioSource audio; private Image imagem; public AudioClip correct, wrong; private bool Ended = false; public List Questoes; [System.Serializable] public class Opcao { public string OP1, OP2, OP3, certo; public Sprite sprite; public AudioClip sportA; } void Awake() { op1 = GameObject.Find("TextOp1").GetComponent(); op2 = GameObject.Find("TextOp2").GetComponent(); op3 = GameObject.Find("TextOp3").GetComponent(); imagem = GameObject.Find("ImageSport").GetComponent(); op1.text = Questoes[Etapa].OP1; op2.text = Questoes[Etapa].OP2; op3.text = Questoes[Etapa].OP3; GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.ended = false; jooj.finishedGame = false; jooj.failedGame = false; } IEnumerator win(int time) { yield return new WaitForSeconds(time); GameControl jooj = GameObject.Find("GameControl").GetComponent(); jooj.finishedGame = true; } 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(win(2)); } else { CorrectSound(); StartCoroutine(resposta(1, Etapa)); Etapa++; op1.text = Questoes[Etapa].OP1; op2.text = Questoes[Etapa].OP2; op3.text = Questoes[Etapa].OP3; imagem.sprite = Questoes[Etapa].sprite; } } else { WrongSound(); txtAnswer.text = "Wrong"; } } } void CorrectSound() { audio.clip = correct; audio.Play(); } void WrongSound() { audio.clip = wrong; audio.Play(); } IEnumerator resposta(int time, int index) { yield return new WaitForSeconds(time); audio.clip = Questoes[index].sportA; audio.Play(); } }