【发布时间】:2017-03-06 08:03:33
【问题描述】:
我的游戏中有一些按钮,我希望主机玩家回答并选择一个按钮来获取此游戏对象按钮的按钮脚本以更改其颜色。
但是我得到了一些这样的错误:
NullReferenceException:对象引用未设置为 对象
这是我的代码:
Button playerOneAnswerBtn = GameObject.FindWithTag (playerOneAnswer).GetComponent<Button> ();
ColorBlock cbPlayerOneAnswer = playerOneAnswerBtn.colors;
cbPlayerOneAnswer.normalColor = Color.blue;
cbPlayerOneAnswer.highlightedColor = Color.blue;
playerOneAnswerBtn.colors = cbPlayerOneAnswer;
【问题讨论】:
-
Debug.Log()FindWithTag()和GetComponent<Button>()的结果。找出空引用在哪里,然后从那里调试。
标签: user-interface button unity3d gameobject