我正在努力制作一个2D砖块破碎机游戏。问题如下:
1)游戏文本和buttons
正在被砖块重叠,如图所示:
2)点击NullReferencException
按钮后,我收到Menu
,如下所示:
NullReferenceException: Object reference not set to an instance of an object
UiManager.Update () (at Assets/UiManager.cs:21)
UiManager脚本是这样的:
public class UiManager : MonoBehaviour {
float score=0;
public Text scoreText;
public Text endText;
public Button[] buttons;
public Text TIMER;
float time=30f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
time -=Time.deltaTime;
TIMER.text = "TIME: " + (int)time;
if (time < 1) {
GameOverF ();
Time.timeScale = 0;
}
}
public void IncrementScore(){
score++;
scoreText.text = "SCORE: " + score;
}
public void IncrementBadScore(){
score-=11;
scoreText.text = "SCORE: " + score;
}
public void IncrementGoodScore(){
score+=11;
scoreText.text = "SCORE: " + score;
}
public void IncrementRedScore(){
score-=2;
scoreText.text = "SCORE: " + score;
}
public void GameOverF(){
endText.gameObject.SetActive (true);
foreach (Button button in buttons) {
button.gameObject.SetActive (true);
}
}
public void exit(){
Application.Quit ();
}
public void Play(){
Application.LoadLevel ("level1");
}
public void Menu(){
Application.LoadLevel ("menu");
}
}
此错误导致我的游戏在我下次点击播放后挂起,所以我只能重新启动游戏!
代码行是这样的:
现在如何删除这些错误?我无法找到帮助!