我正在爲我的項目設計一款遊戲,並且在某個操作後得分(文本)不會更新。它堅持在0.在Unity C中不更新文本#
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class uiManager : MonoBehaviour {
public Text scoreText;
bool gameOver;
int score;
// Use this for initialization
void Start() {
gameOver = false;
score = 0;
InvokeRepeating ("scoreUpdate", 1.0f, 0.5f);
}
// Update is called once per frame
void Update()
{
scoreText.text = "Point: " + score;
}
void scoreUpdate()
{
if (gameOver == false)
{
score += 1;
}
}
public void gameOVER()
{
gameOver = true;
}
public void Play()
{
Application.LoadLevel ("MuachiJump");
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "branch")
{
score += 1;
Destroy(col.gameObject);
}
}
我只是想確定在這段代碼中是否有任何錯誤?他們都似乎是正確的。
請注意,您不應該按照原樣在更新中打印分數。它創建一個新的字符串,並丟棄每一幀的前一個字符串。相反,請在您的樂譜成員上使用一個也更新文本的屬性。這樣,它只會在您更改值時創建一個新的字符串。 – Everts