有人可以修复我的暂停脚本

本文关键字:我的 暂停 脚本 | 更新日期: 2023-09-27 18:06:07

有人可以修复我的暂停菜单脚本吗?(我想让它停止球)这是我的项目链接:http://mediafire.com/download/33poh7jalkcvjzh/Jumpy+ball.rar

使用UnityEngine

;使用System.Collections;

公共类pauseMenu: MonoBehaviour{public GUISkin myskin;

private Rect windowRect;
private bool paused = false , waited = true;
private float time = 60f;
private void Start()
{
    windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
}
private void waiting()
{
    waited = true;
}
private void Update()
{
    if (waited)
        if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
    {
        if (paused)
            paused = false;
        else
            paused = true;
        waited = false;
        Invoke("waiting",0.3f);
    }
    if(!paused)
        if(time>0)
            time -= Time.deltaTime;
}
private void OnGUI()
{
    if (paused)
        windowRect = GUI.Window(0, windowRect, windowFunc, "Pause Menu");
    GUI.Box(new Rect(1, 2, 70, 30), "Time: " + time.ToString("0"));
}
private void windowFunc(int id)
{
    if (GUILayout.Button("Resume"))
    {
        paused = false;
    }
    if (GUILayout.Button ("Restart")) 
    {
        Application.LoadLevel("LEVEL 1");
    }
    if (GUILayout.Button("Quit"))
    {
        Application.LoadLevel("Main Menu");
    }
}

}

有人可以修复我的暂停脚本

使用时间。暂停/取消游戏的时间刻度(即停止球的移动),如下所示:

Time.timeScale = 0f; // paused
Time.timeScale = 1f; // unpaused

请记住,当Time.timeScale为0时,Time.deltaTime将为0,因此在某些情况下您可能需要使用Time.unscaledDeltaTime

用这个代替:

IEnumerator StopBall(float delay)
{
    yield return new WaitForSeconds(delay);
    // Stop the ball code
}

这样写:

StopBall(0.5f);

其中0.5f为您希望等待的时间。记住在数字的末尾加上F,因为它是一个浮点数。问候。