您的位置:首页 > 移动开发 > Unity3D

Unity3D【脚本】 按键盘Esc弹出退出面板 确定退出游戏 取消关闭面板

2014-06-25 13:20 465 查看
按键盘Esc弹出退出面板,确定退出游戏,取消关闭面板。效果图:



脚本:

using UnityEngine;
using System.Collections;

public class Exit : MonoBehaviour {

public GameObject exitPanel = null;	//面板
public UIButton quxiao = null;		//取消按钮
public UIButton queding = null;		//确定按钮

private bool flag = false;

// Use this for initialization
void Start () {
UIEventListener.Get(quxiao.gameObject).onClick += QuXiao;
UIEventListener.Get(queding.gameObject).onClick += QueDing;
exitPanel.SetActive(false);
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape)) {
if (!flag) {
exitPanel.SetActive(true);
flag = true;
} else {
exitPanel.SetActive(false);
flag = false;
}
}
}

void QuXiao(GameObject target) {
exitPanel.SetActive(false);
flag = false;
}

void QueDing(GameObject target) {
Application.Quit();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: