147 lines
3.4 KiB
C#
147 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Aula3_ChooseAlt_Control : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class Question
|
|
{
|
|
public string texto, enunciadoCaller;
|
|
public Sprite enunciadoImg;
|
|
public List<string> ops;
|
|
public int rightOne;
|
|
}
|
|
|
|
public List<Question> questions;
|
|
List<Text> txts; public Image imgShowing;
|
|
List<Image> imgsBtn;
|
|
|
|
public Color cameraColor;
|
|
public Color padrao, acerto, erro;
|
|
public Sprite btnSprite;
|
|
public bool fullscreen, hasText;
|
|
int actualQuestion = 0;
|
|
bool answered = false;
|
|
public bool gameResources; public GamesResourcesFinder resourcesFinder;
|
|
|
|
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>());
|
|
}
|
|
|
|
Camera.main.backgroundColor = cameraColor;
|
|
|
|
if (fullscreen)
|
|
{
|
|
imgShowing = GameObject.Find("ImgShowing Full").GetComponent<Image>();
|
|
Destroy(GameObject.Find("ImgShowing"));
|
|
}
|
|
else
|
|
{
|
|
imgShowing = GameObject.Find("ImgShowing").GetComponent<Image>();
|
|
Destroy(GameObject.Find("ImgShowing Full"));
|
|
}
|
|
|
|
foreach (Image item in imgsBtn)
|
|
{
|
|
item.sprite = btnSprite;
|
|
}
|
|
|
|
if (gameResources)
|
|
{
|
|
StartCoroutine(WaitForDownload());
|
|
}
|
|
else
|
|
{
|
|
ShowQuestion();
|
|
}
|
|
}
|
|
|
|
public IEnumerator WaitForDownload()
|
|
{
|
|
while (!resourcesFinder.gameReady)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
ShowQuestion();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (gameResources)
|
|
{
|
|
imgShowing.sprite = resourcesFinder.AskForImage(question.enunciadoCaller);
|
|
}
|
|
else
|
|
{
|
|
imgShowing.sprite = question.enunciadoImg;
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
yield return new WaitForSecondsRealtime(2);
|
|
|
|
if (actualQuestion >= questions.Count)
|
|
{
|
|
GameControl jooj = GameObject.Find("GameControl").GetComponent<GameControl>();
|
|
jooj.finishedGame = true;
|
|
}
|
|
else
|
|
{
|
|
ShowQuestion();
|
|
answered = false;
|
|
}
|
|
}
|
|
|
|
}
|