Unity UI可以从标签获取文本但无法设置它

时间:2016-03-25 18:39:21

标签: c# unity3d

我有以下属性和方法:

public Text newScore;

public void SaveScore(){
    int score = int.Parse(newScore.text);
    newScore.text = "";
    /* Snipped: Save the value to the database */
}

然后我有一个带有按钮组件的游戏对象。在onClick的那个按钮上我附上了上面的脚本,当我点击按钮时,我能够从Text组件中获取文本,但是我无法将文本重置为空字符串(或其他任何内容)。有什么我想念的吗?

2 个答案:

答案 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 = "";
}