Unity学习之游戏暂停和界面跳转

来源:互联网 发布:vasco软件下载 编辑:程序博客网 时间:2024/05/22 15:59

欢迎大家来到我的博客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/

0 0
原创粉丝点击