1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using UnityEngine; 5 using UnityEngine.UI; 6 7 public class ExitGame : MonoBehaviour 8 { 9 private void Start() {
/*查找按钮组件并添加事件(点击事件)*/ 10 this.GetComponent<Button>().onClick.AddListener(OnClick); 11 } 12 13 /*点击时触发*/ 14 private void OnClick() { 15 /*将状态设置false才能退出游戏*/ 16 UnityEditor.EditorApplication.isPlaying = false; 17 Application.Quit(); 18 } 19 20 21 }