神秘入侵者 发表于 2012-12-19 15:27

Unity3d【坦克大战图文教学3】创建GUI场景切换菜单

本帖最后由 神秘入侵者 于 2012-12-19 15:28 编辑


本节为:【坦克3】创建GUI场景切换菜单

private var menuShow:boolean;

function Start()
{   
    DontDestroyOnLoad(this);
    menuShow=true;
}


function Update () {
    if(Input.GetKeyDown(KeyCode.Escape))
    {
      menuShow=true;
    }
}
function OnGUI()
{
   
    if(menuShow==false)
    {
      return;
    }
    if(GUI.Button(Rect(Screen.width/2-30,Screen.height/2-50,60,30),"Level1"))
    {
      print("You Click The Button Level1");
      Application.LoadLevel(0);
      menuShow=false;
    }
    else if(GUI.Button(Rect(Screen.width/2-30,Screen.height/2-10,60,30),"Level2"))
    {
      print("You Click The Button Level2");
      Application.LoadLevel(1);
      menuShow=false;
    }
      else if(GUI.Button(Rect(Screen.width/2-30,Screen.height/2+30,60,30),"Level3"))
    {
      print("You Click The Button Level3");
      Application.LoadLevel(2);
      menuShow=false;
    }
    else if(GUI.Button(Rect(Screen.width/2-30,Screen.height/2+70,60,30),"Quit"))
    {
      print("You Click The Quit Button!");
      Application.Quit();
      menuShow=false;
    }
}放在menu在场景中即可,然后调用其他场景,按ESC返回menu菜单。
场景的INDEX值在FILE->Building Setting中,选择当前场景,然后点add current即可



感谢论坛提供的资源{:soso_e154:}

hls 发表于 2013-2-24 08:45

楼主太有才了,膜拜中……

rogerj 发表于 2014-1-6 13:53

楼主属于高手,这里学习参考楼主的成果。

362514sc 发表于 2014-4-24 20:39


膜拜中。。。。{:soso__7524161091986203637_5:}

feixiang2835 发表于 2014-6-24 17:31

感谢楼主无私奉献

jinmax 发表于 2017-5-5 11:46

楼主是超人

Copyright 发表于 2017-5-5 11:48

顶顶多好

lj34207310 发表于 2017-5-5 11:51

很好哦

zwpxiaob 发表于 2017-5-5 11:31

不错不错

cpper2003 发表于 2017-5-5 11:31

LZ真是人才
页: [1] 2 3 4 5
查看完整版本: Unity3d【坦克大战图文教学3】创建GUI场景切换菜单