135 lines
3.2 KiB
C#
135 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Aula5_RestaurantChat_Controller : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class Question
|
|
{
|
|
public string textoOther;
|
|
public List<string> ops;
|
|
public int rightOne;
|
|
}
|
|
|
|
public List<Question> questions;
|
|
List<Text> txts; public Image imgShowing;
|
|
List<Image> imgsBtn;
|
|
|
|
public Color padrao, acerto, erro;
|
|
public Sprite btnSprite;
|
|
int actualQuestion = 0;
|
|
bool answered = false;
|
|
|
|
public GameObject playertalks, othertalks;
|
|
Transform trAllign;
|
|
|
|
void Start()
|
|
{
|
|
imgsBtn = new List<Image>() {
|
|
GameObject.Find("BtnOption").GetComponent<Image>(),
|
|
GameObject.Find("BtnOption 2").GetComponent<Image>(),
|
|
GameObject.Find("BtnOption 3").GetComponent<Image>(),
|
|
GameObject.Find("BtnOption 4").GetComponent<Image>()
|
|
};
|
|
|
|
txts = new List<Text>();
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
txts.Add(imgsBtn[i].GetComponentInChildren<Text>());
|
|
}
|
|
|
|
foreach (Image item in imgsBtn)
|
|
{
|
|
item.sprite = btnSprite;
|
|
}
|
|
|
|
trAllign = GameObject.Find("AllignerFalas").transform;
|
|
|
|
ShowQuestion();
|
|
GameControl.instance.StartedGame();
|
|
}
|
|
|
|
public void ShowQuestion()
|
|
{
|
|
Question question = questions[actualQuestion];
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
txts[i].text = question.ops[i];
|
|
}
|
|
|
|
foreach (Image item in imgsBtn)
|
|
{
|
|
item.color = padrao;
|
|
}
|
|
|
|
Instantiate(othertalks, trAllign).GetComponent<Aula5_RestaurantSpeach>().SetInfo(
|
|
questions[actualQuestion].textoOther);
|
|
if ((actualQuestion + 1) == questions.Count)
|
|
{
|
|
StartCoroutine(WaitToFinish());
|
|
}
|
|
|
|
}
|
|
|
|
public void AnswerQuestion(int which)
|
|
{
|
|
if (answered)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (which == questions[actualQuestion].rightOne)
|
|
{
|
|
actualQuestion++;
|
|
|
|
StartCoroutine(RightOne(which));
|
|
}
|
|
else
|
|
{
|
|
imgsBtn[which].color = erro;
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator RightOne(int which)
|
|
{
|
|
answered = true;
|
|
imgsBtn[which].color = acerto;
|
|
|
|
Instantiate(playertalks, trAllign).GetComponent<Aula5_RestaurantSpeach>().SetInfo(
|
|
questions[actualQuestion - 1].ops[which]);
|
|
|
|
yield return new WaitForSecondsRealtime(2);
|
|
|
|
if (actualQuestion == questions.Count)
|
|
{
|
|
FinishGame();
|
|
}
|
|
else
|
|
{
|
|
ShowQuestion();
|
|
answered = false;
|
|
}
|
|
}
|
|
|
|
IEnumerator WaitToFinish()
|
|
{
|
|
for (int i = 0; i < imgsBtn.Count; i++)
|
|
{
|
|
imgsBtn[i].gameObject.SetActive(false);
|
|
}
|
|
yield return new WaitForSecondsRealtime(4);
|
|
|
|
FinishGame();
|
|
}
|
|
|
|
public void FinishGame()
|
|
{
|
|
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
|
|
jooj.finishedGame = true;
|
|
}
|
|
}
|