【发布时间】:2016-03-04 07:31:34
【问题描述】:
我正在使用 Unity C# 制作游戏,并且想要制作 Game Over 场景。
我创建了一个 C# 脚本 (GameOverScript):
using UnityEngine;
using System.Collections;
public class GameOverScript : MonoBehaviour {
int score = 0;
void Start () {
score = PlayerPrefs.GetInt("Score");
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2 - 40, 50, 80, 30), "GAME OVER");
GUI.Label(new Rect(Screen.width / 2 - 40, 300, 80, 30), "Score: " + score);
if (GUI.Button(new Rect(Screen.width / 2 - 30, 350, 60, 30), "Retry?"));
{
Application.LoadLevel(0);
}
}
}
它可以工作,但它只显示大约 2 秒,然后游戏会自动重新启动。代码有什么问题?
【问题讨论】:
-
尝试在Application.LoadLevel(0)之后添加Console.Log("{{some text}}");并检查,也许它会在你现在期望的时候调用它。