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 ops; public int rightOne; } public List questions; List txts; public Image imgShowing; List 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() { GameObject.Find("BtnOption").GetComponent(), GameObject.Find("BtnOption 2").GetComponent(), GameObject.Find("BtnOption 3").GetComponent(), GameObject.Find("BtnOption 4").GetComponent() }; txts = new List(); for (int i = 0; i < 4; i++) { txts.Add(imgsBtn[i].GetComponentInChildren()); } Camera.main.backgroundColor = cameraColor; if (fullscreen) { imgShowing = GameObject.Find("ImgShowing Full").GetComponent(); Destroy(GameObject.Find("ImgShowing")); } else { imgShowing = GameObject.Find("ImgShowing").GetComponent(); 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(); jooj.finishedGame = true; } else { ShowQuestion(); answered = false; } } }