Last active
July 12, 2017 20:04
-
-
Save unity3dcollege/47de39615eccedcf41e6141b47d26d60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class QuizController : MonoBehaviour | |
{ | |
private QuestionCollection questionCollection; | |
private QuizQuestion currentQuestion; | |
private UIController uiController; | |
[SerializeField] | |
private float delayBetweenQuestions = 3f; | |
private void Awake() | |
{ | |
questionCollection = FindObjectOfType<QuestionCollection>(); | |
uiController = FindObjectOfType<UIController>(); | |
} | |
private void Start() | |
{ | |
PresentQuestion(); | |
} | |
private void PresentQuestion() | |
{ | |
currentQuestion = questionCollection.GetUnaskedQuestion(); | |
uiController.SetupUIForQuestion(currentQuestion); | |
} | |
public void SubmitAnswer(int answerNumber) | |
{ | |
bool isCorrect = answerNumber == currentQuestion.CorrectAnswer; | |
uiController.HandleSubmittedAnswer(isCorrect); | |
StartCoroutine(ShowNextQuestionAfterDelay()); | |
} | |
private IEnumerator ShowNextQuestionAfterDelay() | |
{ | |
yield return new WaitForSeconds(delayBetweenQuestions); | |
PresentQuestion(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment