In the Quiz Master tutorial, the instructor shows how to code the buttons to give correct or incorrect answers, and that is what I am trying to achieve. The word ‘sprite’ at the bottom of my code received a red squiggly line. I italicized/asterisked it in the code below. I tried to experiment with the code and looked at the Unity docs before asking here. The error says:
“Image does not contain a definition for ‘sprite’ and no accessible extension method ‘sprite’ accepting a first argument of type ‘Image’ could be found (are you missing a directive or an assembly reference?).”
public class RotG : 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;
}
}
}