Can't find on click() function during "Complete C# Unity Developer 2D" course

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;
        }
    }

I dont have the code in front of me. What is this function doing GetCorrectAnswerIndex()) It is not in your code

How are you getting on with this, @Mikhail_Humphries?

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms