【发布时间】:2016-12-18 08:29:13
【问题描述】:
每当我在游戏结束后点击菜单按钮时,我都会收到这个NullReferenceException。现在由于这个错误,我的游戏挂了,我无法再次重玩。所以我必须重新启动它:
这是错误:
NullReferenceException: Object reference not set to an instance of an object
UiManager.Update () (at Assets/UiManager.cs:21)
这是代码:
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");
}
}
一切都很好,但这个错误即将到来,我无法找出原因? 请帮忙!
【问题讨论】:
标签: c# unity5 unity3d-2dtools