场景转换:varscreenbutton:boolean;functionStart(){DontDestroyOnLoad(this); screenbutton=true;}functionUpdate(){if(()){ screenbutton=true; }}functionOnGUI(){if(screenbutton==true)if((Rect(-380,-190,60,50),"Scene1")){ print("YouclickScene1"); (1); screenbutton=false; }elseif((Rect(-380,-130,60,50),"Scene2")){ print("YouclickScene2"); (2); screenbutton=false; }elseif((Rect(-375,-0,50,50),"Quit")){ print("YouclickQuit"); (); }} 心得:场景转换时,这个程序贴在按钮界面场景中。在BuildSetting(导出)(在File下)菜单中加入所需场景。0为按钮界面。可以无限增加场景。 }elseif((Rect(-380,-130,60,50),"Scene2")){ print("YouclickScene2"); (2); screenbutton=false;复制此段程序并做修改。运动控制键:上下左右varTankSpeed:int=20;functionUpdate(){if(()){ print("go"); (**TankSpeed); }elseif(()){ print("goback"); (**-TankSpeed); }elseif(()){ print("turnleft"); (**-TankSpeed); }elseif(()){ print("turnright"); (**TankSpeed); }}需要放在第一视角的物体或者摄像机上。加天空背景:ponent下的Rendering下的Skybox。将他加在所需场景的摄像机上,选择所需的天空。运行时自然出现。各种按钮汇总:鼠标碰触后显示说明文字。functionOnGUI(){(Rect(0,0,100,20),GUIContent("Clickme","Thisisthetooltip"));(Rect(0,40,100,40),); }多项选择,以上都选择。varallOptions=true;varextended1=true;varextended2=true;functionOnGUI(){allOptions=(Rect(0,120,150,20),allOptions,"EditAllOptions");=allOptions;extended1=(Rect(20,70,130,20),extended1,"ExtendedOption1");extended2=(Rect(20,90,130,20),extended2,"ExtendedOption2");=true;if((Rect(0,160,150,20),"Ok"));print("userclickedok");}鼠标碰触第一个按钮有解释,鼠标碰触第三个对话框有解
Unity3D常用脚本 来自淘豆网m.daumloan.com转载请标明出处.