Button sprite not changing color to display correct answer

Hi there.

I am having an issue with my game. So far I followed everything without a problem until now. When I run my game and click on the correct answer for my quiz question, everything works fine. However when I click on an incorrect answer, the sprite does not highlight the correct answer and an error message is displayed in the console. Please advise.

From what you’ve shown it looks like your script is trying to add an image component to AnswerButton instead of accessing the image component which is already there.

I’m guessing line 41 in your code is supposed to be this:

buttonImage = answerButtons[correctAnswerIndex].GetComponent<Image>();

Is it possible you left off the .GetComponent or something similar?

If my guess is entirely wrong, please share your script so we can see what your line 41 looks like.

1 Like

Thank you I seen the error in my code. I had .AddComponent instead of .GetComponent.

1 Like

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

Privacy & Terms