簡體   English   中英

Game Over Scene不起作用(Unity C#)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM