[Unity3D] 如何实现点击按钮退出游戏

 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 }

 

posted @ 2020-08-30 14:25  伊凡晴天  阅读(13153)  评论(0编辑  收藏  举报