现在的位置: 首页 > 综合 > 正文

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

2018年08月27日 ⁄ 综合 ⁄ 共 695字 ⁄ 字号 评论关闭

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

}

抱歉!评论已关闭.