Quizz: Adding functionnal quizz feature #6
24
Assets/Resources/Questions.json
Normal file
24
Assets/Resources/Questions.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"questions": [
|
||||
{
|
||||
"type": 0,
|
||||
"question": "Quelle est la formule chimique de l'eau ?",
|
||||
"answers": [
|
||||
"H2O",
|
||||
"CO2",
|
||||
"O2",
|
||||
"H2O2"
|
||||
],
|
||||
"good_answer": 0
|
||||
},
|
||||
{
|
||||
"type": 1,
|
||||
"question": "Les isotopes d'un élément ont le même nombre de neutrons.",
|
||||
"answers": [
|
||||
"Vrai",
|
||||
"Faux"
|
||||
],
|
||||
"good_answer": 1
|
||||
}
|
||||
]
|
||||
}
|
7
Assets/Resources/Questions.json.meta
Normal file
7
Assets/Resources/Questions.json.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ba4a065816e43248bb28bbd5e1e304a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,17 +1,41 @@
|
||||
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<Canvas>().enabled = true;
|
||||
TutorialCanvas.GetComponent<Canvas>().enabled = false;
|
||||
Questions.GetComponent<Canvas>().enabled = false;
|
||||
Home.GetComponent<Canvas>().enabled = false;
|
||||
launched = false;
|
||||
started = false;
|
||||
}
|
||||
|
||||
public void ShowTutorial() {
|
||||
@ -23,6 +47,44 @@ public class QuizzManager : MonoBehaviour
|
||||
}
|
||||
|
||||
public void LaunchQuizz() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,16 @@
|
||||
{
|
||||
"name": "Scripts"
|
||||
"name": "Scripts",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@ -1,9 +1,24 @@
|
||||
{
|
||||
"name": "EditMode",
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"Unity.TextMeshPro"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
]
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@ -1,6 +1,22 @@
|
||||
{
|
||||
"name": "PlayMode",
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
]
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"Unity.TextMeshPro"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user