using UnityEngine; /// <summary> /// 双击键盘上的ESC键退出程序 /// </summary> public class KeyEscapQuit : MonoBehaviour { private float lastEscTime; private void Update() { //双击Esc键,退出程序 if (Input.GetKeyDown(KeyCode.Escape)) { if (Time.time - lastEscTime < 0.5f) { Debug.Log(">>> Quit"); #if UNITY_EDITOR //在编辑器中退出Play模式 UnityEditor.EditorApplication.ExitPlaymode(); #else Application.Quit(); #endif } lastEscTime = Time.time; } } }