ZoeAppClass/Assets/Jogos/292/Scripts/Ctrl292.cs

90 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Ctrl292 : MonoBehaviour
{
private int Etapa = 0;
private Text op1, op2, op3, Enunciado;
public AudioSource audio;
private Image imagem;
public AudioClip correct, wrong;
private bool Ended = false;
public List<Opcao> Questoes;
[System.Serializable]
public class Opcao
{
public string OP1, OP2, OP3, certo, enunciado;
}
// Start is called before the first frame update
void Start()
{
op1 = GameObject.Find("TextOp1").GetComponent<Text>();
op2 = GameObject.Find("TextOp2").GetComponent<Text>();
op3 = GameObject.Find("TextOp3").GetComponent<Text>();
Enunciado = GameObject.Find("Enunciado").GetComponent<Text>();
op1.text = Questoes[Etapa].OP1;
op2.text = Questoes[Etapa].OP2;
op3.text = Questoes[Etapa].OP3;
Enunciado.text = Questoes[Etapa].enunciado;
GameControl jooj = GameControl.instance;
}
// Update is called once per frame
void Update()
{
}
public void VerificaResposta(Text Answer)
{
if (!Ended)
{
Text txtAnswer = Answer.gameObject.GetComponentInChildren<Text>();
if (txtAnswer.text == Questoes[Etapa].certo)
{
if ((Etapa + 1) == Questoes.Count)
{
CorrectSound();
StartCoroutine(win(2));
}
else
{
CorrectSound();
Etapa++;
op1.text = Questoes[Etapa].OP1;
op2.text = Questoes[Etapa].OP2;
op3.text = Questoes[Etapa].OP3;
Enunciado.text = Questoes[Etapa].enunciado;
}
}
else
{
WrongSound();
txtAnswer.text = "Wrong";
}
}
}
IEnumerator win(int time)
{
yield return new WaitForSeconds(time);
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
jooj.finishedGame = true;
}
void CorrectSound()
{
audio.clip = correct;
audio.Play();
}
void WrongSound()
{
audio.clip = wrong;
audio.Play();
}
}