Unity 游戏场景

Application 函数

Application.LoaddLevel(“名称或者索引”); //加载场景,5.6.0以上过时, 修改方法
Application.OpenURL("www.baidu.com"); //运行时自动打开网站 Application.CaptureScreenshot("1.jpg"); //保存图片在项目根目录上,注意图片格式

游戏暂停,并切换Scene场景(切换关卡)
if(time.timeScale >0 && input.getkeydown(keycode.escape)){
Time.timeScale = 0;
Application.LoadLevel (“Scene场景名称 or Scene场景index索引”);
}
注:File->Build Settings->Add Current->(勾选Scene场景) ( 要加载的场景在这里添加)

简单数据场景存储 (数据存在注册表中)
1- 设置:(在一个Scene中)
PlayerPrefs.SetInt(“life”,100);
PlayerPrefs.SetFloat(“lev”,9.8f);
PlayerPrefs.SetString(“name”,“zhangsan”);

注: 此方法可以跨Scene调用一些比较简单的数据

2- 读取(在另一个Scene中)
PlayerPrefs.GetInt(“life”);
PlayerPrefs.GetFloat(“lev”);
PlayerPrefs.GetString(“name”);

猜你喜欢

转载自blog.csdn.net/czhenya/article/details/77008595