Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7.  
  8. public class GameManager : MonoBehaviour
  9. {
  10. public float roundDelay = 1.25f;
  11. private int currentRound = 1;
  12.  
  13. public Text rounds;
  14. public Text questionText;
  15.  
  16. public List<Question> allQuestions;
  17. public List<Question> answeredQuestions;
  18. public List<Question> answersUsedThisRound;
  19. public List<Button> options;
  20. [HideInInspector]
  21. public Button correctAnswer;
  22.  
  23. public int rndButton;
  24.  
  25.  
  26. private void Start()
  27. {
  28. Game();
  29. }
  30.  
  31. public void Game()
  32. {
  33. while (true)
  34. {
  35. answersUsedThisRound.Clear();
  36. int randomQuestion = Random.Range(0, allQuestions.Count);
  37. if (!answeredQuestions.Contains(allQuestions[randomQuestion]))
  38. {
  39. questionText.text = allQuestions[randomQuestion].question;
  40. answeredQuestions.Add(allQuestions[randomQuestion]);
  41.  
  42. rndButton = Random.Range(0, options.Count);
  43. options[rndButton].GetComponent<Reader>().text.text = allQuestions[randomQuestion].answer;
  44. answersUsedThisRound.Add(allQuestions[randomQuestion]);
  45. correctAnswer = options[rndButton];
  46.  
  47. break;
  48. }
  49. else if(allQuestions.Count == answeredQuestions.Count)
  50. {
  51. SceneManager.LoadScene(0);
  52. break;
  53. }
  54. }
  55.  
  56. FillRest();
  57. RoundManager();
  58. }
  59.  
  60. public void FillRest()
  61. {
  62. foreach(Button btn in options)
  63. {
  64. if(btn != options[rndButton])
  65. {
  66. while(btn.transform.GetComponent<Reader>().question == null)
  67. {
  68. int rndQuestion = Random.Range(0, allQuestions.Count);
  69.  
  70. if (!answersUsedThisRound.Contains(allQuestions[rndQuestion]))
  71. {
  72. btn.GetComponent<Reader>().question = allQuestions[rndQuestion];
  73. answersUsedThisRound.Add(allQuestions[rndQuestion]);
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. public void RoundManager()
  81. {
  82. rounds.text = $"{currentRound} / {allQuestions.Count}";
  83. }
  84.  
  85. public IEnumerator NewRound()
  86. {
  87. yield return new WaitForSeconds(roundDelay);
  88. currentRound++;
  89. foreach(Button btn in options)
  90. {
  91. btn.interactable = true;
  92. btn.GetComponent<Image>().color = Color.white;
  93. btn.GetComponent<Reader>().question = null;
  94. }
  95.  
  96. Game();
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement