Unity学习之游戏暂停和界面跳转
2014-12-30 21:18
369 查看
欢迎大家来到我的博客http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
跳转界面操作
使用Application.LoadLevel (加载关卡)
这个函数按照索引加载关卡。在Unity中使用File->Build Settings.....菜单可以看到所有 关卡的索引列表。在你能过加载关卡之前你必须将它添加到游戏使用关卡列表中。在 Unity中使用File->Build Settings.....并添加你需要的关卡到关卡列表中。
添加关卡列表后即可使用Application.LoadLevel(int index)来跳转游戏场景
void OnGUI(){
if(GUI.Button (new Rect(300,200,100,30),"进入游戏")){
Application.LoadLevel(1);
}else if(GUI.Button (new Rect(300,280,100,30),"操作说明")){
Application.LoadLevel (2);
}
}
在游戏中暂停,继续游戏的操作
float time;
void Update () {
if(flag){
Time.timeScale=0;
}else{
Time.timeScale=time;
if(Input.GetKey (KeyCode.Escape)){
time=0;
}else if(Input.GetMouseButton (0)){
time=1;
}
}
}
显示玩家生命,分数的界面
void OnGUI(){
GUI.TextField (new Rect(20,20,100,20),"生命值:"+player.i);
GUI.TextField (new Rect(20,40,100,20),"得分:"+player.score);
if(player==null){
flag=true;
GUI.skin.label.fontSize = 30;
GUI.color = Color.red;
GUI.Label (new Rect(300,110,200,80),"逗比,这都过不去");
GUI.color=Color.white;
if(GUI.Button (new Rect(300,200,100,30),"重新开始")){
Application.LoadLevel (1);
}else if(GUI.Button (new Rect(300,250,100,30),"返回主页")){
Application.LoadLevel (0);
}
}
}
请继续关注我的博客
http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
更多精彩尽在http://www.gopedu.com/
跳转界面操作
使用Application.LoadLevel (加载关卡)
这个函数按照索引加载关卡。在Unity中使用File->Build Settings.....菜单可以看到所有 关卡的索引列表。在你能过加载关卡之前你必须将它添加到游戏使用关卡列表中。在 Unity中使用File->Build Settings.....并添加你需要的关卡到关卡列表中。
添加关卡列表后即可使用Application.LoadLevel(int index)来跳转游戏场景
void OnGUI(){
if(GUI.Button (new Rect(300,200,100,30),"进入游戏")){
Application.LoadLevel(1);
}else if(GUI.Button (new Rect(300,280,100,30),"操作说明")){
Application.LoadLevel (2);
}
}
在游戏中暂停,继续游戏的操作
float time;
void Update () {
if(flag){
Time.timeScale=0;
}else{
Time.timeScale=time;
if(Input.GetKey (KeyCode.Escape)){
time=0;
}else if(Input.GetMouseButton (0)){
time=1;
}
}
}
显示玩家生命,分数的界面
void OnGUI(){
GUI.TextField (new Rect(20,20,100,20),"生命值:"+player.i);
GUI.TextField (new Rect(20,40,100,20),"得分:"+player.score);
if(player==null){
flag=true;
GUI.skin.label.fontSize = 30;
GUI.color = Color.red;
GUI.Label (new Rect(300,110,200,80),"逗比,这都过不去");
GUI.color=Color.white;
if(GUI.Button (new Rect(300,200,100,30),"重新开始")){
Application.LoadLevel (1);
}else if(GUI.Button (new Rect(300,250,100,30),"返回主页")){
Application.LoadLevel (0);
}
}
}
请继续关注我的博客
http://unity.gopedu.com/home.php?mod=space&uid=3352&do=blog&view=me&from=space
更多精彩尽在http://www.gopedu.com/
相关文章推荐
- 小韵游戏开发学习笔记——第三期:Unity工程创建及界面功能的基本介绍
- 【Unity 3D】学习笔记二十:基础2D游戏界面
- [知了堂学习笔记]_用JS制作《飞机大作战》游戏_第2讲(四大界面之间的跳转与玩家飞机的移动)
- Unity 让游戏暂停的方法
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(1)之 loading 界面编写
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2dx 游戏界面跳转到其他activity
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- libgdx游戏引擎开发笔记(八)SuperJumper游戏例子的讲解(篇二)---- 游戏界面跳转
- android 平台搭建学习01--第一个界面的菜单设置及与其他三个界面的相互跳转(天气预报系统)
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(5)之 游戏主界面 -----主界面美化--魔法阵和自定义弹出框
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(3)之 游戏主界面 -----武器系统---散花弹
- cocos2d-x 实现按Home和待机键后,再进入游戏显示暂停界面
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(4)之 游戏主界面 -----怪物系统---赌徒来袭
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(5)之 游戏主界面 -----主界面美化--魔法阵和自定义弹出框
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(6)之 游戏主界面 -----绚丽的魔法特效
- Unity学习系类笔记5:多人游戏基础
- cocos2d-x 实现按Home和待机键后,再进入游戏显示暂停界面
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(1)之 loading 界面编写
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(2)之 欢迎 界面编写