Skip to content

Instantly share code, notes, and snippets.

@unity3dcollege
Last active July 12, 2017 20:04
Show Gist options
  • Save unity3dcollege/47de39615eccedcf41e6141b47d26d60 to your computer and use it in GitHub Desktop.
Save unity3dcollege/47de39615eccedcf41e6141b47d26d60 to your computer and use it in GitHub Desktop.
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