I can’t get OnAnswerSelected to show up for me in the drop down tab for my buttons, I have the image type sliced, I’ve looked over my code. A few things are different for me than in the instructors videos. When he has to hold “control + .” over image to add unityUI, I did not, it automatically added “using Microsoft.Unity.VisualStudio.Editor;” on its own. Below are my two codes. Please Help
This is my quiz script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Microsoft.Unity.VisualStudio.Editor;
public class Quiz : MonoBehaviour
{
[SerializeField] TextMeshProUGUI questionText;
[SerializeField] QuestionSO question;
[SerializeField] GameObject[] answerButtons;
int correctAnswerIndex;
[SerializeField] Sprite defaultAnswerSprite;
[SerializeField] Sprite correctAnswerSprite;
void Start()
{
questionText.text = question.GetQuestion();
for (int i = 0; i < answerButtons.Length; i++)
{
TextMeshProUGUI buttonText = answerButtons[i].GetComponentInChildren<TextMeshProUGUI>();
buttonText.text = question.GetAnswer(i);
}
}
public void OnAnswerSelected(int index)
{
if(index == question.GetCorrectAnswerIndex())
{
questionText.text = "Correct!";
Image buttonImage = answerButtons[index].GetComponent<Image>();
buttonImage.sprite = correctAnswerSprite;
}
}
}
This is my QuestionSO script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = “Quiz Question”, fileName = “NewQuestion”)]
public class QuestionSO : ScriptableObject
{
[TextArea(2,6)]
[SerializeField] string question = "Enter new question text here";
[SerializeField] string[] answers = new string[4];
[SerializeField] int correctAnswerIndex;
public string GetQuestion()
{
return question;
}
public string GetAnswer(int index)
{
return answers[index];
}
public int GetCorrectAnswerIndex()
{
return correctAnswerIndex;
}
}