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


按键盘Esc弹出退出面板,确定退出游戏,取消关闭面板。效果图:

Unity3D【脚本】 按键盘Esc弹出退出面板 确定退出游戏 取消关闭面板_第1张图片

脚本:

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

}





你可能感兴趣的:(Unity3D)