Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- public class QuizManager : MonoBehaviour
- {
- public float timeRandom;
- TextMeshProUGUI textSoal,textTime,textA, textB, textC, textD;
- //private int random;
- public List<Quest> quest;
- [System.Serializable]
- public class Quest
- {
- public string soal;
- public string pilA, pilB, pilC, pilD;
- public bool A, B, C, D;
- }
- // Start is called before the first frame update
- void Start()
- {
- textTime = GameObject.Find("Time Text").GetComponent<TextMeshProUGUI>();
- textSoal = GameObject.Find("QuestionText").GetComponent<TextMeshProUGUI>();
- textA = GameObject.Find("A").GetComponent<TextMeshProUGUI>();
- textB = GameObject.Find("B").GetComponent<TextMeshProUGUI>();
- textC = GameObject.Find("C").GetComponent<TextMeshProUGUI>();
- textD = GameObject.Find("D").GetComponent<TextMeshProUGUI>();
- //random = Random.RandomRange(0, quest.Count);
- Shuffle(quest);
- }
- // Update is called once per frame
- void Update()
- {
- textTime.text = "" + timeRandom.ToString("0");
- timeRandom -= Time.deltaTime;
- if (timeRandom <= 0)
- {
- quest.RemoveAt(random);
- timeRandom = 5;
- random = Random.RandomRange(0, quest.Count);
- }
- textSoal.text = quest[random].soal;
- textA.text = quest[random].pilA;
- textB.text = quest[random].pilB;
- textC.text = quest[random].pilC;
- textD.text = quest[random].pilD;
- }
- void Shuffle<T>(List<T> list)
- {
- System.Random random = new System.Random();
- int n = list.Count;
- while (n > 1)
- {
- int k = random.Next(0, n);
- n--;
- T temp = list[k];
- list[k] = list[n];
- list[n] = temp;
- }
- }
- /*for (int Quest = 0; Quest < quest.Count; Quest++)
- {
- T temp = quest[Quest];
- int random = Random.Range(0, quest.Count);
- quest[Quest] = quest[random];
- quest[random] = temp;
- }*/
- /*public void Correct(string answer)
- {
- if (Quest[random].A==true && answer=="a")
- {
- PlayerController.isSafeOpen = true;
- }
- if (Quest[random].B==true && answer=="b")
- {
- PlayerController.isSafeOpen = true;
- }
- if (Quest[random].C==true && answer=="c")
- {
- PlayerController.isSafeOpen = true;
- }
- if (Quest[random].D==true && answer=="d")
- {
- PlayerController.isSafeOpen = true;
- }
- //Quest.RemoveAt(random);
- //random = Random.RandomRange(0, Quest.Count);
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement