Unity3D常用脚本
varscreenbutton:boolean;functionStart()DontDestroyOnLoad(this);screenbutton=true;functionUpdate()if)screenbutton=true;functionOnGUI()if(screenbutton=true)if(Rect2-380,2-190,60,50),"Scene1")print("YouclickScene1");(1);screenbutton=false;elseif(Rect2-380,2-130,60,50),"Scene2")print("YouclickScene2");(2);screenbutton=false;elseif(Rect2-375,2-0,50,50),"Quit")print("YouclickQuit");();心得:场景转换时,这个程序贴在按钮界面场景中。在BuildSetting(导出)(在File下)菜单中加入所需场景。0为按钮界面。可以无限增加场景。elseif(Rect2-380,2-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);需要放在第一视角的物体或者摄像机上。加天空背景:菜单栏Component下的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");鼠标碰触第一个按钮有解释,鼠标碰触第三个对话框有解释。碰第二个没有解释。functionOnGUI()(Rect(5,300,110,75),GUIContent("Box","Thisboxhasatooltip");(Rect(10,230,100,20),"Notooltiphere");(Rect(10,200,100,20),GUIContent("Ihaveatooltip","Thebuttonoverridesthebox");(Rect(10,260,100,40),;半透明,说明性文字对话框。无选择。functionUpdate()functionOnGUI()(newRect/2-400,/2-300,800,600);(newRect(0,0,800,600),"Thisboxisnowcentered!-hereyouwouldputyourmainmenu");();滚动条,选择按钮。可以放多个按钮并且节省位置。functionUpdate()varscrollPosition=;functionOnGUI()scrollPosition=(Rect(10,400,100,100),scrollPosition,Rect(0,0,220,200);(Rect(0,0,100,20),"Top-left");(Rect(120,0,100,20),"Top-right");(Rect(0,180,100,20),"Bottom-left");(Rect(120,180,100,20),"Bottom-right");();循环的字幕。varletterPause=;vardel:boolean=false;varparticle:GameObject;functionStart()DontDestroyOnLoad(this);screnbutton=true;word=Text;Text=""yieldWaitForSeconds(2);TypeText();functionUpdate()if)screnbutton=true;if(Text="Thisiszcxfirstproject!Icandoit.")Text=""TypeText();if(0)Text=""for(varc:charin(Youwanttoonlyturncharacterbutnottiltit)Makethecameraachildofthecapsule.Resetit'stransform.(Youwantthecameratotiltupanddownlikeahead.Thecharacteralreadyturns.)AddComponentMenu("Camera-Control/MouseLook")publicclassCameraMoveRotate:MonoBehaviourpublicenumRotationAxesMouseXAndY=0,MouseX=1,MouseY=2publicRotationAxesaxes=;publicfloatsensitivityX=15F;publicfloatsensitivityY=15F;publicfloatminimumX=-360F;publicfloatmaximumX=360F;publicfloatminimumY=-60F;publicfloatmaximumY=60F;publicfloatmoveSpeed=;floatrotationX=0F;floatrotationY=0F;QuaternionoriginalRotation;voidUpdate()break;1.2. 3.4. 5.