1.新建场景命名为“BtnQuit”
2.在场景中新建“UI”----“Button”按钮,
3.新建C#脚本,命名为“Quit”
编写脚本,如下:using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Quit : MonoBehaviour {
public void BtnQuit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
4.拖拽脚本赋给按钮属性。
修改属性,添加脚本程序方法。