Unity3D【指令碼】 按鍵盤Esc彈出退出面板 確定退出遊戲 取消關閉面板
阿新 • • 發佈:2019-01-25
按鍵盤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(); } }