有人可以修复我的暂停菜单脚本吗?(我想让它停止播放)以下是我项目的链接:http://mediafire.com/download/33poh7jalkcvjzh/Jumpy+ball.rar
使用UnityEngine; 使用System.Collections;
public class pauseMenu:MonoBehaviour { 公共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");
}
}
}
答案 0 :(得分:1)
使用Time.timeScale暂停/取消暂停游戏(即阻止球移动),如下所示:
Time.timeScale = 0f; // paused
Time.timeScale = 1f; // unpaused
请记住Time.deltaTime
为0时Time.timeScale
将为0,因此在某些情况下您可能希望使用Time.unscaledDeltaTime
。
答案 1 :(得分:0)
请改用:
IEnumerator StopBall(float delay)
{
yield return new WaitForSeconds(delay);
// Stop the ball code
}
这样称呼:
StopBall(0.5f);
其中0.5f是您要等待的金额。请记住将 F 添加到数字的末尾,因为它是浮点数。问候。