我有以下属性和方法:
public Text newScore;
public void SaveScore(){
int score = int.Parse(newScore.text);
newScore.text = "";
/* Snipped: Save the value to the database */
}
然后我有一个带有按钮组件的游戏对象。在onClick的那个按钮上我附上了上面的脚本,当我点击按钮时,我能够从Text组件中获取文本,但是我无法将文本重置为空字符串(或其他任何内容)。有什么我想念的吗?
答案 0 :(得分:0)
因此,对于InputField
,该组件具有text
字段。
使用GameObject
的{{1}}字段,而不是使用Text
组件中的InputField
组件来更改值,而不是text
public InputField newScore;
public void SaveScore(){
int score = int.Parse(newScore.text);
newScore.text = "";
/* Snipped: Save the value to the database */
}
字段。
<div ng-repeat="graph in myGraphs" class="graph transition-200">
<div> {{ graph.svg }} </div>
</div>
答案 1 :(得分:0)
您使用的是InputField,如果是这样的话,请改用:
InputField field;
void Start ()
{
field.text = "";
}