Last active
July 12, 2017 20:04
-
-
Save unity3dcollege/51fdc08cf8125fe9e4f0ea6c7f1f3eda 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; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class UIController : MonoBehaviour | |
{ | |
[SerializeField] | |
private Text questionText; | |
[SerializeField] | |
private Button[] answerButtons; | |
[SerializeField] | |
private GameObject correctAnswerPopup; | |
[SerializeField] | |
private GameObject wrongAnswerPopup; | |
public void SetupUIForQuestion(QuizQuestion question) | |
{ | |
correctAnswerPopup.SetActive(false); | |
wrongAnswerPopup.SetActive(false); | |
questionText.text = question.Question; | |
for (int i = 0; i < question.Answers.Length; i++) | |
{ | |
answerButtons[i].GetComponentInChildren<Text>().text = question.Answers[i]; | |
answerButtons[i].gameObject.SetActive(true); | |
} | |
for (int i = question.Answers.Length; i < answerButtons.Length; i++) | |
{ | |
answerButtons[i].gameObject.SetActive(false); | |
} | |
} | |
public void HandleSubmittedAnswer(bool isCorrect) | |
{ | |
ToggleAnswerButtons(false); | |
if (isCorrect) | |
{ | |
ShowCorrectAnswerPopup(); | |
} | |
else | |
{ | |
ShowWrongAnswerPopup(); | |
} | |
} | |
private void ToggleAnswerButtons(bool value) | |
{ | |
for (int i = 0; i < answerButtons.Length; i++) | |
{ | |
answerButtons[i].gameObject.SetActive(value); | |
} | |
} | |
private void ShowCorrectAnswerPopup() | |
{ | |
correctAnswerPopup.SetActive(true); | |
} | |
private void ShowWrongAnswerPopup() | |
{ | |
wrongAnswerPopup.SetActive(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment