2024-01-08 22:03:29 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2024-01-10 17:14:23 +01:00
|
|
|
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;
|
|
|
|
}
|
2024-01-08 22:03:29 +01:00
|
|
|
|
|
|
|
public class QuizzManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject LoadingCanvas;
|
|
|
|
public GameObject TutorialCanvas;
|
2024-01-10 17:14:23 +01:00
|
|
|
public GameObject Questions;
|
|
|
|
public GameObject Home;
|
|
|
|
public TextAsset jsonFile;
|
2024-01-08 22:03:29 +01:00
|
|
|
private bool launched;
|
2024-01-10 17:14:23 +01:00
|
|
|
private bool started;
|
|
|
|
private int answer_button;
|
2024-01-08 22:03:29 +01:00
|
|
|
|
|
|
|
void Start() {
|
|
|
|
LoadingCanvas.GetComponent<Canvas>().enabled = true;
|
|
|
|
TutorialCanvas.GetComponent<Canvas>().enabled = false;
|
2024-01-10 17:14:23 +01:00
|
|
|
Questions.GetComponent<Canvas>().enabled = false;
|
|
|
|
Home.GetComponent<Canvas>().enabled = false;
|
2024-01-08 22:03:29 +01:00
|
|
|
launched = false;
|
2024-01-10 17:14:23 +01:00
|
|
|
started = false;
|
2024-01-08 22:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ShowTutorial() {
|
|
|
|
if (!launched) {
|
|
|
|
LoadingCanvas.GetComponent<Canvas>().enabled = false;
|
|
|
|
TutorialCanvas.GetComponent<Canvas>().enabled = true;
|
|
|
|
launched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void LaunchQuizz() {
|
2024-01-10 17:14:23 +01:00
|
|
|
if (!started) {
|
|
|
|
TutorialCanvas.GetComponent<Canvas>().enabled = false;
|
|
|
|
Home.GetComponent<Canvas>().enabled = true;
|
|
|
|
started = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void LeaveApp() {
|
|
|
|
Application.Quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void YesNoQuestion(Question question) {
|
|
|
|
GameObject.Find("Question").GetComponent<TMP_Text>().text = question.question;
|
|
|
|
GameObject.Find("AnswerA").GetComponentInChildren<TMP_Text>().text = question.answers[0];
|
|
|
|
GameObject.Find("AnswerB").GetComponentInChildren<TMP_Text>().text = question.answers[1];
|
|
|
|
GameObject.Find("HidingCanva").GetComponent<Canvas>().enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ClassicQuestion(Question question) {
|
|
|
|
GameObject.Find("Question").GetComponent<TMP_Text>().text = question.question;
|
|
|
|
GameObject.Find("HidingCanva").GetComponent<Canvas>().enabled = true;
|
|
|
|
GameObject.Find("AnswerA").GetComponentInChildren<TMP_Text>().text = question.answers[0];
|
|
|
|
GameObject.Find("AnswerB").GetComponentInChildren<TMP_Text>().text = question.answers[1];
|
|
|
|
GameObject.Find("AnswerC").GetComponentInChildren<TMP_Text>().text = question.answers[2];
|
|
|
|
GameObject.Find("AnswerD").GetComponentInChildren<TMP_Text>().text = question.answers[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartQuizz() {
|
|
|
|
Home.GetComponent<Canvas>().enabled = false;
|
|
|
|
Questions.GetComponent<Canvas>().enabled = true;
|
|
|
|
Questions questions = JsonUtility.FromJson<Questions>(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);
|
|
|
|
}
|
|
|
|
}
|
2024-01-08 22:03:29 +01:00
|
|
|
}
|
|
|
|
}
|