Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour
- {
- public float roundDelay = 1.25f;
- private int currentRound = 1;
- public Text rounds;
- public Text questionText;
- public List<Question> allQuestions;
- public List<Question> answeredQuestions;
- public List<Question> answersUsedThisRound;
- public List<Button> options;
- [HideInInspector]
- public Button correctAnswer;
- public int rndButton;
- private void Start()
- {
- Game();
- }
- public void Game()
- {
- while (true)
- {
- answersUsedThisRound.Clear();
- int randomQuestion = Random.Range(0, allQuestions.Count);
- if (!answeredQuestions.Contains(allQuestions[randomQuestion]))
- {
- questionText.text = allQuestions[randomQuestion].question;
- answeredQuestions.Add(allQuestions[randomQuestion]);
- rndButton = Random.Range(0, options.Count);
- options[rndButton].GetComponent<Reader>().text.text = allQuestions[randomQuestion].answer;
- answersUsedThisRound.Add(allQuestions[randomQuestion]);
- correctAnswer = options[rndButton];
- break;
- }
- else if(allQuestions.Count == answeredQuestions.Count)
- {
- SceneManager.LoadScene(0);
- break;
- }
- }
- FillRest();
- RoundManager();
- }
- public void FillRest()
- {
- foreach(Button btn in options)
- {
- if(btn != options[rndButton])
- {
- while(btn.transform.GetComponent<Reader>().question == null)
- {
- int rndQuestion = Random.Range(0, allQuestions.Count);
- if (!answersUsedThisRound.Contains(allQuestions[rndQuestion]))
- {
- btn.GetComponent<Reader>().question = allQuestions[rndQuestion];
- answersUsedThisRound.Add(allQuestions[rndQuestion]);
- }
- }
- }
- }
- }
- public void RoundManager()
- {
- rounds.text = $"{currentRound} / {allQuestions.Count}";
- }
- public IEnumerator NewRound()
- {
- yield return new WaitForSeconds(roundDelay);
- currentRound++;
- foreach(Button btn in options)
- {
- btn.interactable = true;
- btn.GetComponent<Image>().color = Color.white;
- btn.GetComponent<Reader>().question = null;
- }
- Game();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement