using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; [System.Serializable] public class Question { public string question; public string[] answers; public int good_answer; public int type; } [System.Serializable] public class Questions { public Question[] questions; } public class QuizzManager : MonoBehaviour { public GameObject LoadingCanvas; public GameObject TutorialCanvas; public GameObject Questions; 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; Questions.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 YesNoQuestion(Question question) { GameObject.Find("Question").GetComponent().text = question.question; GameObject.Find("AnswerA").GetComponentInChildren().text = question.answers[0]; GameObject.Find("AnswerB").GetComponentInChildren().text = question.answers[1]; GameObject.Find("HidingCanva").GetComponent().enabled = false; } private void ClassicQuestion(Question question) { GameObject.Find("Question").GetComponent().text = question.question; GameObject.Find("HidingCanva").GetComponent().enabled = true; GameObject.Find("AnswerA").GetComponentInChildren().text = question.answers[0]; GameObject.Find("AnswerB").GetComponentInChildren().text = question.answers[1]; GameObject.Find("AnswerC").GetComponentInChildren().text = question.answers[2]; GameObject.Find("AnswerD").GetComponentInChildren().text = question.answers[3]; } public void StartQuizz() { Home.GetComponent().enabled = false; Questions.GetComponent().enabled = true; Questions questions = JsonUtility.FromJson(jsonFile.text); for (int i = 0; i < questions.questions.Length; i++) { Question question = questions.questions[i]; if (question.type == 0) { ClassicQuestion(question); } else { YesNoQuestion(question); } } } }