Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine.SceneManagement;
- public class GameManager : MonoBehaviour {
- public Question[] questions;
- private static List<Question> UnansweredQuestions;
- private Question currentQuestion;
- [SerializeField]
- private Text factText;
- [SerializeField]
- private Text trueAnswerText;
- [SerializeField]
- private Text falseAnswerText;
- [SerializeField]
- private Animator animator;
- [SerializeField]
- private float timeBetweenQuestions = 1f;
- void Start ()
- {
- if (UnansweredQuestions == null || UnansweredQuestions.Count == 0)
- {
- UnansweredQuestions = questions.ToList<Question>();
- }
- SetCurrentQuestion ();
- }
- void SetCurrentQuestion()
- {
- int randomQuestionIndex = Random.Range (0, UnansweredQuestions.Count);
- currentQuestion = UnansweredQuestions [randomQuestionIndex];
- factText.text = currentQuestion.fact;
- if (currentQuestion.isTrue) {
- trueAnswerText.text = "CORRECT";
- falseAnswerText.text = "FALSE";
- } else
- {
- trueAnswerText.text = "WRONG";ø
- falseAnswerText.text = "CORRECT";
- }
- }
- IEnumerator TransitionToNextQuestion ()
- {
- UnansweredQuestions.Remove(currentQuestion);
- yield return new WaitForSeconds (timeBetweenQuestions);
- SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex );
- }
- public void UserSelectTrue ()
- {
- animator.SetTrigger("True");
- if (currentQuestion.isTrue)
- {
- Debug.Log ("correct");
- }else
- { Debug.Log ("Wrong");
- }
- StartCoroutine(TransitionToNextQuestion());
- }
- public void UserSelectFalse ()
- {
- animator.SetTrigger("False");
- if (!currentQuestion.isTrue)
- {
- Debug.Log ("correct");
- }else
- { Debug.Log ("Wrong");
- }
- StartCoroutine(TransitionToNextQuestion());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement