using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; [System.Serializable] public class aQuestion { public string aquestion; public string[] answers; public int good_answer; public int type; } [System.Serializable] public class aQuestions { public aQuestion[] aquestions; } public class QsuizzManager : MonoBehaviour { public GameObject LoadingCanvas; public GameObject TutorialCanvas; public GameObject aQuestions; public GameObject Home; public TextAsset jsonFile; private bool launched; private bool started; private int answer_button; void Start() { LoadingCanvas.GetComponent().enabled = true; TutorialCanvas.GetComponent().enabled = false; aQuestions.GetComponent().enabled = false; Home.GetComponent().enabled = false; launched = false; started = false; } public void ShowTutorial() { if (!launched) { LoadingCanvas.GetComponent().enabled = false; TutorialCanvas.GetComponent().enabled = true; launched = true; } } public void LaunchQuizz() { if (!started) { TutorialCanvas.GetComponent().enabled = false; Home.GetComponent().enabled = true; started = true; } } public void LeaveApp() { Application.Quit(); } private void YesNoaQuestion(aQuestion aquestion) { GameObject.Find("aQuestion").GetComponent().text = aquestion.aquestion; GameObject.Find("AnswerA").GetComponentInChildren().text = aquestion.answers[0]; GameObject.Find("AnswerB").GetComponentInChildren().text = aquestion.answers[1]; GameObject.Find("HidingCanva").GetComponent().enabled = false; } private void ClassicaQuestion(aQuestion aquestion) { GameObject.Find("aQuestion").GetComponent().text = aquestion.aquestion; GameObject.Find("HidingCanva").GetComponent().enabled = true; GameObject.Find("AnswerA").GetComponentInChildren().text = aquestion.answers[0]; GameObject.Find("AnswerB").GetComponentInChildren().text = aquestion.answers[1]; GameObject.Find("AnswerC").GetComponentInChildren().text = aquestion.answers[2]; GameObject.Find("AnswerD").GetComponentInChildren().text = aquestion.answers[3]; } public void StartQuizz() { Home.GetComponent().enabled = false; aQuestions.GetComponent().enabled = true; aQuestions aquestions = JsonUtility.FromJson(jsonFile.text); for (int i = 0; i < aquestions.aquestions.Length; i++) { aQuestion aquestion = aquestions.aquestions[i]; if (aquestion.type == 0) { ClassicaQuestion(aquestion); } else { YesNoaQuestion(aquestion); } } } }