Hi,
I am busy doing the complete C# unity developer 2d course, however, I am stuck.
I’ve been trying to find this OnAnswerSelected function dropdown but I can’t tell what I did wrong. This is the code I was given.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class Quiz : MonoBehaviour
{
[SerializeField] TextMeshProUGUI questionText;
[SerializeField] QuestionSO question;
[SerializeField] GameObject[] answerButtons;
int correctAnswerIndex;
[SerializeField] Sprite defaultAnswerSprite;
[SerializeField] Sprite correctAnswerSprite;
public void Start()
{
for(int i = 0; i < answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
buttonText.text = question.GetAnswer(i);
}
questionText.text = question.GetQuestion();
}
public void OnAnswerSelected(int index)
{
if(index == question.GetCorrectAnswerIndex())
{
questionText.text = "correct";
Image buttonImage = answerButtons[index].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
}