Swapping Sprites

For the swapping sprites section of Quiz Master my script doesn’t seem to work and yet I can’t find an issue. I have even compared it to the resource.

What doesn’t work?

Please copy code instead of screenshots. it makes it a lot easier to help. You can have a look here:

to see how to format code correctly

when I hit play it says there is a compilier error. here is a copy of the code.

‘’’
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;



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;

}

}

}
‘’’

What is the error. It will help if I knew that. This code does not have any compiler errors I can see.

Also, the code format characters are back-ticks (usually found above the Tab key) not single quotes

lol ok sorry, just says compilier error, usually I miss a capital or something but i can’t find anything wrong, and with the bottons to do the swap won’t give me the OnAnswer function from Quiz.cs . I went through it 3 times and still can’t find the problem.

It’s all good, just trying to get enough info. The console will show the errors

Assets\Scripts\Quiz.cs(38,26): error CS1061: ‘QuestionSO’ does not contain a definition for ‘GetCorrectAnswerIndex’ and no accessible extension method ‘GetCorrectAnswerIndex’ accepting a first argument of type ‘QuestionSO’ could be found (are you missing a using directive or an assembly reference?)

ok didn’t realise that if you click on the red button this showed up.

So thanks to that figured out my mistake from the QuestionSO.cs lol

Does that mean the problem is solved? :slight_smile:


See also:

yes, sorry and thanks for the help.

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

Privacy & Terms