有人可以修复我的暂停脚本吗?
Can someone fix my pause script?
有人可以修复我的暂停菜单脚本吗?(我想让它停下来)这是我项目的 link:http://mediafire.com/download/33poh7jalkcvjzh/Jumpy+ball.rar
使用UnityEngine;
使用 System.Collections;
public class 暂停菜单: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");
}
}
}
改用这个:
IEnumerator StopBall(float delay)
{
yield return new WaitForSeconds(delay);
// Stop the ball code
}
这样称呼它:
StopBall(0.5f);
其中 0.5f 是您要等待的金额。请记住将 F 添加到数字的末尾,因为它是一个浮点数。问候。
使用 Time.timeScale 到 pause/unpause 游戏(即停止球移动),像这样:
Time.timeScale = 0f; // paused
Time.timeScale = 1f; // unpaused
请记住,当 Time.timeScale
为 0 时,Time.deltaTime
将为 0,因此在某些情况下您可能需要使用 Time.unscaledDeltaTime
。
有人可以修复我的暂停菜单脚本吗?(我想让它停下来)这是我项目的 link:http://mediafire.com/download/33poh7jalkcvjzh/Jumpy+ball.rar
使用UnityEngine; 使用 System.Collections;
public class 暂停菜单: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");
}
}
}
改用这个:
IEnumerator StopBall(float delay)
{
yield return new WaitForSeconds(delay);
// Stop the ball code
}
这样称呼它:
StopBall(0.5f);
其中 0.5f 是您要等待的金额。请记住将 F 添加到数字的末尾,因为它是一个浮点数。问候。
使用 Time.timeScale 到 pause/unpause 游戏(即停止球移动),像这样:
Time.timeScale = 0f; // paused
Time.timeScale = 1f; // unpaused
请记住,当 Time.timeScale
为 0 时,Time.deltaTime
将为 0,因此在某些情况下您可能需要使用 Time.unscaledDeltaTime
。