资源描述:
《Unity3D常用脚本.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.场景转换:varscreenbutton:boolean;functionStart(){DontDestroyOnLoad(this);screenbutton=true;}functionUpdate(){if(Input.GetKeyDown(KeyCode.Escape)){screenbutton=true;}}functionOnGUI(){if(screenbutton==true)if(GUI.Button(Rect(Screen.width/2-380,Screen.height/
2、2-190,60,50),"Scene1")){print("YouclickScene1");Application.LoadLevel(1);screenbutton=false;}elseif(GUI.Button(Rect(Screen.width/2-380,Screen.height/2-130,60,50),"Scene2")){print("YouclickScene2");Application.LoadLevel(2);screenbutton=false;}elseif(GUI.
3、Button(Rect(Screen.width/2-375,Screen.height/2-0,50,50),"Quit")){print("YouclickQuit");Application.Quit();}}心得:场景转换时,这个程序贴在按钮界面场景中。在BuildSetting(导出)(在File下)菜单中加入所需场景。Word资料.0为按钮界面。可以无限增加场景。}elseif(GUI.Button(Rect(Screen.width/2-380,Screen.height/2-130,6
4、0,50),"Scene2")){print("YouclickScene2");Application.LoadLevel(2);screenbutton=false;复制此段程序并做修改。运动控制键:上下左右varTankSpeed:int=20;functionUpdate(){if(Input.GetKey(KeyCode.W)){print("go");transform.Translate(Vector3.forward*Time.deltaTime*TankSpeed);}elseif(
5、Input.GetKey(KeyCode.S)){print("goback");transform.Translate(Vector3.forward*Time.deltaTime*-TankSpeed);}elseif(Input.GetKey(KeyCode.A)){print("turnleft");transform.Rotate(Vector3.up*Time.deltaTime*-TankSpeed);}elseif(Input.GetKey(KeyCode.D)){print("tur
6、nright");Word资料.transform.Rotate(Vector3.up*Time.deltaTime*TankSpeed);}}需要放在第一视角的物体或者摄像机上。加天空背景:菜单栏Component下的Rendering下的Skybox。将他加在所需场景的摄像机上,选择所需的天空。运行时自然出现。各种按钮汇总:Word资料.鼠标碰触后显示说明文字。functionOnGUI(){GUI.Button(Rect(0,0,100,20),GUIContent("Clickme","Thi
7、sisthetooltip"));GUI.Label(Rect(0,40,100,40),GUI.tooltip);}多项选择,以上都选择。varallOptions=true;varextended1=true;varextended2=true;functionOnGUI(){allOptions=GUI.Toggle(Rect(0,120,150,20),allOptions,"EditAllOptions");GUI.enabled=allOptions;extended1=GUI.Toggl
8、e(Rect(20,70,130,20),extended1,"ExtendedOption1");extended2=GUI.Toggle(Rect(20,90,130,20),extended2,"ExtendedOption2");Word资料.GUI.enabled=true;if(GUI.Button(Rect(0,160,150,20),"Ok"));print("userclickedok");}鼠标碰触第一个按钮有解释,鼠标碰触第三个对话