按键盘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(); } }