[英]Game Over Scene doesn't work (Unity C#)
我正在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秒钟,游戏会自动重新启动。 代码有什么问题?
请删除; (位于if条件之后)
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);
}
您熟悉IEnumerator函数吗? 我倾向于延迟的方式是使用WaitForSeconds()
。 例如,
IEnumerator PauseFunc(){
yield return new WaitForSeconds(5); //5 second pause
}
然后,在您上面的代码中进行备份,以启动CoRoutine。 StartCoroutine( “PauseFunc”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.