Question by
SaritaW · Aug 20, 2018 at 05:04 AM ·
unity 5c# tutorialquiz
unity quiz game tutorial - continue displaying current question until correct answer button is clicked.
In the quiz game tutorial, either I click on correct or wrong answer button it takes me to the next question. (just that score is increased by 1 if the correct answer is clicked). But I want to stick to the same question until the correct answer is clicked.and if the wrong answer is clicked then I want to change the text colour to red just to notify that wrong answer was clicked. can anyone please help me to understand how it works. I tried using wait for seconds before loading next question but nothing works.
// Use this for initialization
void Start ()
{
dataController = FindObjectOfType<DataController>();
currentRoundData = dataController.GetCurrentRoundData();
questionPool = currentRoundData.questions;
timeRemaining = currentRoundData.timeLimitSeconds;
UpdateTimeRemainingDisplay();
playerScore = 0;
questionIndex = 0;
ShowQuestion();
isRoundActive = true;
}
private void ShowQuestion()
{
// StartCoroutine(waiter());
RemoveAnswerButtons();
ChooseQuestion();
QuestionData questionData = questionPool[questionIndex];
questionText.text = questionData.questionText;
for (int i = 0; i < questionData.answers.Length; i++)
{
GameObject answerButtonGameObject = answerButtonObjectPool.GetObject();
answerButtonGameObjects.Add(answerButtonGameObject);
answerButtonGameObject.transform.SetParent(answerButtonParent);
AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton>();
answerButton.Setup(questionData.answers[i]);
}
}
public void AnswerButtonClicked (bool isCorrect)
{
if (isCorrect)
{
playerScore += currentRoundData.pointAddedForCorrectAnswer;
scoreDisplayText.text = "Score: " + playerScore.ToString();
//play coorect answer sound
answerButtonClicked.Play();
//change button color
tempButton = AnswerButton.GetComponent<Button>();
colorBlockHuman = tempButton.colors;
colorBlockHuman.pressedColor = new Color(90, 179, 32, 255);
tempButton.colors = colorBlockHuman;
}
if (!isCorrect)
{
//play wrong answer sound
answerButtonClicked = wrongAnswerClicked;
answerButtonClicked.Play();
//change button color
tempButton = AnswerButton.GetComponent<Button>();
colorBlockHuman = tempButton.colors;
colorBlockHuman.pressedColor = new Color(195, 0, 0, 255);
tempButton.colors = colorBlockHuman;
}
Comment