Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using UnityEngine.SceneManagement;
  7.  
  8. public class GameManager : MonoBehaviour {
  9.  
  10. public Question[] questions;
  11. private static List<Question> UnansweredQuestions;
  12.  
  13. private Question currentQuestion;
  14.  
  15. [SerializeField]
  16. private Text factText;
  17.  
  18. [SerializeField]
  19. private Text trueAnswerText;
  20. [SerializeField]
  21. private Text falseAnswerText;
  22.  
  23. [SerializeField]
  24. private Animator animator;
  25.  
  26.  
  27. [SerializeField]
  28. private float timeBetweenQuestions = 1f;
  29.  
  30. void Start ()
  31. {
  32. if (UnansweredQuestions == null || UnansweredQuestions.Count == 0)
  33. {
  34. UnansweredQuestions = questions.ToList<Question>();
  35. }
  36.  
  37. SetCurrentQuestion ();
  38.  
  39. }
  40. void SetCurrentQuestion()
  41. {
  42. int randomQuestionIndex = Random.Range (0, UnansweredQuestions.Count);
  43. currentQuestion = UnansweredQuestions [randomQuestionIndex];
  44.  
  45. factText.text = currentQuestion.fact;
  46.  
  47. if (currentQuestion.isTrue) {
  48. trueAnswerText.text = "CORRECT";
  49. falseAnswerText.text = "FALSE";
  50. } else
  51. {
  52. trueAnswerText.text = "WRONG";ø
  53. falseAnswerText.text = "CORRECT";
  54. }
  55.  
  56. }
  57.  
  58. IEnumerator TransitionToNextQuestion ()
  59. {
  60. UnansweredQuestions.Remove(currentQuestion);
  61.  
  62. yield return new WaitForSeconds (timeBetweenQuestions);
  63.  
  64. SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex );
  65. }
  66.  
  67.  
  68. public void UserSelectTrue ()
  69. {
  70. animator.SetTrigger("True");
  71.  
  72. if (currentQuestion.isTrue)
  73. {
  74. Debug.Log ("correct");
  75. }else
  76.  
  77. { Debug.Log ("Wrong");
  78.  
  79. }
  80. StartCoroutine(TransitionToNextQuestion());
  81. }
  82.  
  83. public void UserSelectFalse ()
  84. {
  85. animator.SetTrigger("False");
  86.  
  87. if (!currentQuestion.isTrue)
  88. {
  89. Debug.Log ("correct");
  90. }else
  91.  
  92. { Debug.Log ("Wrong");
  93.  
  94. }
  95. StartCoroutine(TransitionToNextQuestion());
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement