【发布时间】:2013-11-29 00:38:20
【问题描述】:
我有一个代码向用户显示他们是否真的想退出游戏的是/否问题。这是我的代码:
using UnityEngine;
using System.Collections;
public class UserPrompt : MonoBehaviour {
public int count = 0;
public bool paused = false;
public static UserPrompt Instance;
// Use this for initialization
void Awake ()
{
if (Instance == null)
{
Instance = this;
}
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
paused = true;
count = 1;
}
if(paused)
Time.timeScale = 0;
else
Time.timeScale = 1;
}
void OnGUI ()
{
if(count == 1)
{
GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
GUI.Label(new Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6), "Do you really want quit to main menu ?");
if(GUI.Button(new Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
Application.LoadLevel("Menu");
if(GUI.Button(new Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
{
paused = false;
count = 0;
}
}
}
}
问题是我应该点击“继续播放”按钮两次才能消失,似乎这段代码会为每个 GUI 对象创建两次,但我看不出有什么问题。
提前致谢
【问题讨论】:
标签: unity3d