码迷,mamicode.com
首页 > 编程语言 > 详细

unity 退出程序按钮实现

时间:2017-07-11 16:40:41      阅读:1388      评论:0      收藏:0      [点我收藏+]

标签:运行   技术分享   ati   enter   sys   color   修改属性   png   editor   

退出程序按钮实现

 

 

 

 

1.新建场景命名为Quit

2.在场景中新建UI----Button”按钮,

 

 

 

修改按钮的文本属性,输入“退出”(或者关闭)

 

3.新建C#脚本,命名为“Btn_Quit

编写脚本,如下:

using UnityEngine;
using System.Collections;

public class Btn_Quit : MonoBehaviour {
public void Quit (){

#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}

 

4.回到场景中,拖拽脚本赋给按钮属性。

技术分享

 

 

修改属性,添加脚本程序方法。

 技术分享

最终属性如下:

技术分享

 

 

点击运行,然后点击按钮,就会发现退出运行程序了。

unity 退出程序按钮实现

标签:运行   技术分享   ati   enter   sys   color   修改属性   png   editor   

原文地址:http://www.cnblogs.com/jiangyuzhen/p/7151132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!