如何代替application.islevel loadingglevel

.Quit 退出
static function Quit () : void
Description描述
Quits the player application. Quit is ignored in the editor or the web player.
退出应用程序。在编辑器或者web播放器中退出被忽略。
IMPORTANT: This function has no effect on
iPhone. Termination of application under iPhone OS should be left at the
user discretion.
Consult Apple's Technical Q&A qa1561 page for further details:
/iphone/library/qa/qa2008/qa1561.html
这个函数对iPhone没有效果,根据iPhone应用程序终止操作系统应让用户自行决定。咨询苹果的技术问答 /iphone/library/qa/qa2008/qa1561.html
using UnityE
using System.C
public class example :
void Update() {
if (Input.GetKey(&escape&))
Application.Quit();
// Quits the player when the user hits escape
//当用户点击Esc建时退出播放器
function Update () {
if (Input.GetKey (&escape&)) {
Application.Quit();
本脚本参考基于Unity 3.4.1f5英文部分版权属&公司所有,中文部分&
版权所有,未经许可,严禁转载 。unity(186)
在游戏项目中,常常会使用到用户信息,获取信息当然可以从数据库中获取。但是对场景多的游戏这样做是不正确的,那么我我们就需要再第一次获取用户信息之后,
同时在其它的场景中共享用户数据,避免对服务器增加负担。好的!现在上图
首先新建第一个场景,命名为one
场景中物体如下:
接着我们新建第二个场景:two
其中场景对象如下:
这样做一个简单的区分,以便测试。
制作思想:
在前一个场景中,添加新的EmptyGameObject,同时制作脚本PersistentData.cs,在脚本中添加一些全局变量。在游戏加载下一个场景的时候,使用
Object.DontDestroyOnLoad()方法进行保护。使得有关的数据得以持久化!
1、PersistentData.cs
using UnityE
using System.C
public class PersistentData : MonoBehaviour {
public &string userName=&&;
public &string pwd=&&;
// Use this for initialization
void Start () {
// Update is called once per frame
void Update () {
if (Application.isLoadingLevel)
& &Object.DontDestroyOnLoad(gameObject);
在场景one中,添加空游戏物体,同时附加如上的代码.
同时呢,在场景的相机上添加user.cs文件
using UnityE
using System.C
public class user : MonoBehaviour {
public float width=0.0f;
public float height=0.0f;
public string levelName=&&;
private string _name=&&;
private string _pwd=&&;
// Use this for initialization
void Start () {
// Update is called once per frame
void Update () {
void OnGUI() {
GUILayout.BeginVertical(GUILayout.Width(200));
GUILayout.BeginHorizontal(GUILayout.Width(200));
GUILayout.Label(&Name:&);
_name= GUILayout.TextField(_name,10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.Width(200));
GUILayout.Label(&passWord:&);
_pwd= GUILayout.TextField(_pwd,10);
& &GUILayout.EndHorizontal();
if (GUILayout.Button(&login&,GUILayout.Width(80),GUILayout.Height(60)))
//save data 保存数据到PersistentData的变量中
GameObject.Find(&data&).GetComponent&PersistentData&().userName = _
GameObject.Find(&data&).GetComponent&PersistentData&().pwd = _
Application.LoadLevel(&two&);
GUILayout.EndVertical();
然后在场景two中,给相机添加上PersistentDataGetting.cs文件
代码如下:
using UnityE
using System.C
public class PersistentDataGetting : MonoBehaviour {
private string userName=&&;
private string pwd=&&;
private PersistentData pdS
// Use this for initialization
void Start () {
&pdScript = GameObject.Find(&data&).GetComponent&PersistentData&();
&userName = pdScript.userN
&pwd = pdScript.
// Update is called once per frame
void Update () {
void OnGUI(){
& & & & & & & &//用户信息显示
GUI.Label(new Rect(Screen.width/2,Screen.height/2,100,30),userName);
GUI.Label(new Rect(Screen.width/2, Screen.height/2+40,100,30), pwd);
最终效果:
当然数据持久话的方式还有很多,这是其中一种,各有各的优缺点,要根据你存储的数据而定了。
欢迎大家加入梦想之家 游戏讨论群& & & &
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:303397次
积分:4511
积分:4511
排名:第5541名
原创:108篇
转载:265篇
评论:29条
(1)(5)(9)(10)(13)(23)(11)(21)(24)(18)(32)(12)(23)(30)(44)(35)(62)(4)1.1.2 loadedLevel属性:关卡索引
本文所属图书&>&
本书挑选了Unity 引擎里一些核心API 类,例如 Object、GameObject、Rigidbody、Transform、Camera、Quaternion、Vector3 等进行了详细的功能注解,注解内容包括API 的使用方法、算法分析、边界条件、参数间&&
基本语法public static int loadedLevel { }
功能说明此属性用于返回当前程序最后加载的关卡(即Scene)的索引值(只读)。
实例演示下面通过实例演示loadedLevel属性的使用方法。
using UnityE
using System.C
public class LoadedLevel_ts : MonoBehaviour
&&& void Start()
&&&&&&& //返回当前场景的索引值
&&&&&&& Debug.Log(&loadedLevel:& + Application.loadedLevel);
&&&&&&& //返回当前场景的名字
&&&&&&& Debug.Log(&loadedLevelName:& + Application.loadedLevelName);
&&&&&&& //是否有场景正在被加载
//在使用Application类的静态方法LoadLevel或LoadLevelAdditive加载一个新的场景时,
//常常需要持续一段时间才能加载完毕,当场景加载完毕时,isLoadingLevel返回true,
//否则返回false
&&&&&&& Debug.Log(&isLoadingLevel:& + Application.isLoadingLevel);
&&&&&&& //返回游戏中可被加载的场景数量
&&&&&&& Debug.Log(&levelCount:& + Application.levelCount);
&&&&&&& //返回当前游戏的运行平台
//游戏的运行平台有很多种,例如手机、电脑、游戏机等,具体类型可在枚举类
//RuntimePlatform中查看
&&&&&&& Debug.Log(&platform:& + Application.platform);
&&&&&&& //当前游戏是否正在运行
&&&&&&& Debug.Log(&isPlaying:& + Application.isPlaying);
&&&&&&& //当前游戏是否处于Unity编辑模式
&&&&&&& Debug.Log(&isEditor:& + Application.isEditor);
在这段代码中,分别打印出了Application类的一些常用静态属性,具体的属性功能请参考代码中的注释。图1-2是代码执行的输出结果,其中levelCount的值为2,这是因为在BuildSettings(File&BuildSettings)中有两个场景,具体请到工程中查看。
您对本文章有什么意见或着疑问吗?请到您的关注和建议是我们前行的参考和动力&&
您的浏览器不支持嵌入式框架,或者当前配置为不显示嵌入式框架。您所在的位置: &
1.1.2 loadedLevel属性:关卡索引
1.1.2 loadedLevel属性:关卡索引
人民邮电出版社
《Unity API解析》第1章Application类,本章主要介绍Application类的一些静态属性和静态方法。本节为大家介绍loadedLevel属性:关卡索引。
1.1.2 loadedLevel属性:关卡索引
基本语法&public static int loadedLevel { }
功能说明&此属性用于返回当前程序最后加载的关卡(即Scene)的索引值(只读)。
实例演示&下面通过实例演示loadedLevel属性的使用方法。
using&UnityE &using&System.C &public&class&LoadedLevel_ts&:&MonoBehaviour &{ &&&&&void&Start() &&&&&{ &&&&&&&&&//返回当前场景的索引值 &&&&&&&&&Debug.Log("loadedLevel:"&+&Application.loadedLevel); &&&&&&&&&//返回当前场景的名字 &&&&&&&&&Debug.Log("loadedLevelName:"&+&Application.loadedLevelName); &&&&&&&&&//是否有场景正在被加载 &//在使用Application类的静态方法LoadLevel或LoadLevelAdditive加载一个新的场景时, &//常常需要持续一段时间才能加载完毕,当场景加载完毕时,isLoadingLevel返回true, &//否则返回false &&&&&&&&&Debug.Log("isLoadingLevel:"&+&Application.isLoadingLevel); &&&&&&&&&//返回游戏中可被加载的场景数量 &&&&&&&&&Debug.Log("levelCount:"&+&Application.levelCount); &&&&&&&&&//返回当前游戏的运行平台 &//游戏的运行平台有很多种,例如手机、电脑、游戏机等,具体类型可在枚举类 &//RuntimePlatform中查看 &&&&&&&&&Debug.Log("platform:"&+&Application.platform); &&&&&&&&&//当前游戏是否正在运行 &&&&&&&&&Debug.Log("isPlaying:"&+&Application.isPlaying); &&&&&&&&&//当前游戏是否处于Unity编辑模式 &&&&&&&&&Debug.Log("isEditor:"&+&Application.isEditor); &&&&&} &}&
在这段代码中,分别打印出了Application类的一些常用静态属性,具体的属性功能请参考代码中的注释。图1-2是代码执行的输出结果,其中levelCount的值为2,这是因为在BuildSettings(File→BuildSettings)中有两个场景,具体请到工程中查看。
喜欢的朋友可以添加我们的微信账号:
51CTO读书频道二维码
51CTO读书频道活动讨论群:【责任编辑: TEL:(010)】
关于&&的更多文章
本书挑选了Unity 引擎里一些核心API 类,例如 Object、GameObjec
本书描述了黑客用默默无闻的行动为数字世界照亮了一条道路的故事。
讲师: 1人学习过讲师: 31人学习过讲师: 292人学习过
历史不是镜子,历史是精子,牺牲亿万,才有一个活到今
通计近30个动手实践的案例,循序渐进的展示Spark Grap
《自己动手写CPU(含CD光盘1张)》使用Verilog HDL 设计
本书选择经典的开放源代码,全面系统地分析了Linux安全机制。本书共有17章,前10章着重介绍了Linux操作系统的安全机制及实现方法
51CTO旗下网站

我要回帖

更多关于 jquery isloading 的文章

 

随机推荐