153 lines
3.7 KiB
C#
153 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameClothe09 : MonoBehaviour
|
|
{
|
|
public Text Enunciado;
|
|
public AudioSource audioAcertos, audioEnun;
|
|
public AudioClip[] audiosDialogo, dialogo2;
|
|
public AudioClip correct, wrong;
|
|
private bool Ended;
|
|
public List<Opcao> Questoes;
|
|
[System.Serializable]
|
|
public class Opcao
|
|
{
|
|
public string Certo;
|
|
}
|
|
|
|
int acertosEtapa1, acertosEtapa2;
|
|
|
|
bool wonEtapa1, wonEtapa2;
|
|
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
|
|
StartCoroutine(playAudioSequentially());
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void ButtonReplay()
|
|
{
|
|
int etapa = GetComponent<Animator>().GetInteger("etapa");
|
|
|
|
if(etapa == 0)
|
|
{
|
|
StartCoroutine( playAudioSequentially());
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(playAudioSequentially2());
|
|
}
|
|
}
|
|
public void VerificaResposta(string Answer, GameClothe09Objs obj)
|
|
{
|
|
if (!Ended)
|
|
{
|
|
int etapa = GetComponent<Animator>().GetInteger("etapa");
|
|
if (Answer == Questoes[etapa].Certo)
|
|
{
|
|
switch (etapa)
|
|
{
|
|
case 0:
|
|
acertosEtapa1++;
|
|
break;
|
|
case 1:
|
|
acertosEtapa2++;
|
|
break;
|
|
}
|
|
|
|
if ((acertosEtapa1 + acertosEtapa2) >= 11)
|
|
{
|
|
CorrectSound();
|
|
win();
|
|
}
|
|
else
|
|
{
|
|
obj.SetRight();
|
|
CorrectSound();
|
|
|
|
switch (etapa)
|
|
{
|
|
case 0:
|
|
acertosEtapa1++;
|
|
GameObject.Find("Acertos 1").GetComponent<Text>().text = acertosEtapa1 + " / 6";
|
|
break;
|
|
case 1:
|
|
acertosEtapa2++;
|
|
GameObject.Find("Acertos 2").GetComponent<Text>().text = acertosEtapa2 + " / 5";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WrongSound();
|
|
obj.SetWrong();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ChangeEtapa()
|
|
{
|
|
int etapa = GetComponent<Animator>().GetInteger("etapa");
|
|
|
|
if (etapa == 0)
|
|
{
|
|
GetComponent<Animator>().SetInteger("etapa", 1);
|
|
StartCoroutine(playAudioSequentially2());
|
|
}
|
|
else
|
|
{
|
|
GetComponent<Animator>().SetInteger("etapa", 0);
|
|
StartCoroutine(playAudioSequentially());
|
|
}
|
|
}
|
|
|
|
void win()
|
|
{
|
|
GameControl.instance.FinishGame();
|
|
}
|
|
|
|
void CorrectSound()
|
|
{
|
|
audioAcertos.clip = correct;
|
|
audioAcertos.Play();
|
|
}
|
|
|
|
void WrongSound()
|
|
{
|
|
audioAcertos.clip = wrong;
|
|
audioAcertos.Play();
|
|
}
|
|
|
|
IEnumerator playAudioSequentially()
|
|
{
|
|
yield return null;
|
|
for (int i = 0; i < audiosDialogo.Length; i++)
|
|
{
|
|
audioEnun.clip = audiosDialogo[i];
|
|
audioEnun.Play();
|
|
while (audioEnun.isPlaying)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
IEnumerator playAudioSequentially2()
|
|
{
|
|
yield return null;
|
|
for (int i = 0; i < dialogo2.Length; i++)
|
|
{
|
|
audioEnun.clip = dialogo2[i];
|
|
audioEnun.Play();
|
|
while (audioEnun.isPlaying)
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
}
|