Unity Quiz游戏,选择正确答案时突出显示按钮

我想在选择正确答案时将按钮突出显示为绿色,我该怎么做?

AnswerButton附加到脚本中

public class AnswerButton : MonoBehaviour { public Text answerText; private GameController gameController; private AnswerData answerData; void Start() { gameController = FindObjectOfType(); } public void SetUp(AnswerData data) { answerData = data; answerText.text = answerData.answerText; } public void HandleClick() { gameController.AnswerButtonClicked(answerData.isCorrect); } } 

我的游戏控制器按住按钮和Q n A.

 public void AnswerButtonClicked(bool isCorrect) { if (isCorrect) { Debug.Log("Your Answer is Correct"); playerScore += currentRoundData.pointsAddedForCorrectAnswer; // If the AnswerButton that was clicked was the correct answer, add points scoreDisplay.text = playerScore.ToString(); } if (qNumber < questionPool.Length - 1) // If there are more questions, show the next question { qNumber++; ShowQuestion(); } else // If there are no more questions, the round ends { EndRound(); } } 

非常简单,如果您的按钮上有图像,这样的东西应该可以工作

 GetComponent().color = Color.green; 

我也见过这样的代码

  ColorBlock colors = GetComponent 

请注意,如果按钮已经着色,则会将绿色与现有颜色混合,因此请为按钮选择中性色,如白色或浅灰色。