我写了以下代码来保持游戏的分数。
private GameObject scoreobject;
private int score;
public void InstantiateScore()
{
score = 0;
scoreobject = GameObject.Find("scoretext");
//scoreobject.transform.position = new Vector2(0, 0);
}
public void UpdateScore(){
score++;
scoreobject = GameObject.Find("scoretext");
if (scoreobject)
{
scoreobject.guiText.text = score.ToString();
}
}
问题出在评论行scoreobject.transform.position = new Vector2(0, 0);
中。当我尝试更改我的scoreobject的位置时,该对象不会出现在屏幕上。