ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:429.30KB ,
资源ID:12642650      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/12642650.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Unity3D常用脚本.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Unity3D常用脚本.docx

1、Unity3D常用脚本场景转换:var screenbutton: boolean;function Start() DontDestroyOnLoad(this); screenbutton = true;function Update () if(Input.GetKeyDown(KeyCode.Escape) screenbutton = true; function OnGUI() if(screenbutton=true) if(GUI。Button(Rect(Screen。width/2380,Screen。height/2-190,60,50),Scene1)) print(”Y

2、ou click Scene1”); Application.LoadLevel (1); screenbutton = false; else if(GUI.Button(Rect(Screen。width/2-380,Screen.height/2130,60,50),Scene2”) print(You click Scene2); Application。LoadLevel (2); screenbutton = false; else if( GUI。Button(Rect(Screen。width/2375,Screen。height/20,50,50),”Quit”)) prin

3、t(You click Quit); Application.Quit(); 心得:场景转换时,这个程序贴在按钮界面场景中。在Build Setting(导出)(在File下)菜单中加入所需场景。0为按钮界面。可以无限增加场景。 else if(GUI.Button(Rect(Screen。width/2-380,Screen.height/2130,60,50),”Scene2”)) print(You click Scene2); Application.LoadLevel (2); screenbutton = false;复制此段程序并做修改。运动控制键:上下左右var TankSpe

4、ed:int = 20;function Update () if(Input.GetKey(KeyCode。W) print(go); transform。Translate(Vector3。forward Time.deltaTime * TankSpeed); else if(Input.GetKey(KeyCode.S)) print(”go back”); transform.Translate(Vector3.forward Time。deltaTime TankSpeed); else if(Input。GetKey(KeyCode。A)) print(”turn left”);

5、 transform.Rotate(Vector3.up Time。deltaTime -TankSpeed); else if(Input。GetKey(KeyCode.D) print(”turn right); transform.Rotate(Vector3。up Time.deltaTime * TankSpeed); 需要放在第一视角的物体或者摄像机上.加天空背景:菜单栏Component下的Rendering下的Skybox。将他加在所需场景的摄像机上,选择所需的天空。运行时自然出现。各种按钮汇总:鼠标碰触后显示说明文字。function OnGUI () GUI.Button

6、(Rect (0, 0, 100, 20), GUIContent (”Click me”, This is the tooltip)); GUI。Label (Rect (0, 40, 100, 40), GUI。tooltip); 多项选择,以上都选择。var allOptions = true;var extended1 = true;var extended2 = true;function OnGUI () allOptions = GUI.Toggle (Rect (0,120,150,20), allOptions, ”Edit All Options);GUI。enabled

7、= allOptions;extended1 = GUI.Toggle (Rect (20,70,130,20), extended1, Extended Option 1”);extended2 = GUI。Toggle (Rect (20,90,130,20), extended2, Extended Option 2”);GUI。enabled = true;if (GUI.Button (Rect (0, 160, 150, 20), Ok”));print (user clicked ok”);鼠标碰触第一个按钮有解释,鼠标碰触第三个对话框有解释。碰第二个没有解释。function

8、OnGUI () GUI.Box (Rect (5, 300, 110, 75), GUIContent (”Box, This box has a tooltip);GUI。Button (Rect (10, 230, 100, 20), No tooltip here”);GUI.Button (Rect (10, 200, 100, 20),GUIContent (”I have a tooltip”, The button overrides the box));GUI.Label (Rect (10,260,100,40), GUI.tooltip); 半透明,说明性文字对话框。无选

9、择。function Update () function OnGUI () GUI。BeginGroup (new Rect (Screen.width / 2 400, Screen.height / 2 300, 800, 600);GUI。Box (new Rect (0,0,800,600),This box is now centered! - here you would put your main menu”);GUI.EndGroup ();滚动条,选择按钮.可以放多个按钮并且节省位置。function Update () var scrollPosition = Vecto

10、r2.zero;function OnGUI () scrollPosition = GUI。BeginScrollView (Rect (10,400,100,100),scrollPosition, Rect (0, 0, 220, 200);GUI.Button (Rect (0,0,100,20), ”Topleft);GUI.Button (Rect (120,0,100,20), ”Top-right);GUI。Button (Rect (0,180,100,20), ”Bottomleft”);GUI。Button (Rect (120,180,100,20), ”Bottom-

11、right”);GUI。EndScrollView (); 循环的字幕。var letterPause = 0。2;/定义每个字出现的时间间隔 var sound : AudioClip;/打字机的声音 private var word;/存储你打字机效果想要输出的字的变量 private var Text : String = My name is Ray Yang。Keep it in your heart!;/你希望打字机效果输出的字 function Start () word = Text;/把你输出的字先赋值给word Text = ”;/把你要显示的字先抹除,以便你可以在最初显示

12、的时候显示为空,当然你也可以加上其他字,让他先显示,打字机效果打的字会显示在这个后面 yield WaitForSeconds (2); TypeText (); function OnGUI () GUI。Label (Rect(150,15,250,25),Please answer my question,who am I?); GUI。Box (Rect(150,40,250,25),Text); function TypeText () for (var letter in word。ToCharArray()) /做一个循环,定义一个变量letter逐次等于word中的每一个字符

13、Text += letter;/把这些字赋值给Text if (sound)/控制声音,出现一个字,发一个声音 audio.PlayOneShot (sound); yield WaitForSeconds (letterPause); function Update () if(Text = word) Text=”; TypeText(); 有打字声音的字幕循环。var screnbutton:boolean;var icon : Texture;var allOptions = true;var extended1 = true;var extended2 = true;var lett

14、erPause = 0.2;/定义每个字出现的时间间隔 var sound : AudioClip;/打字机的声音 private var word;/存储你打字机效果想要输出的字的变量 static var Text : String = ”This is zcx first project! I can do it.”;var del : boolean = false;var particle : GameObject;function Start()DontDestroyOnLoad(this);screnbutton=true;word = Text;Text = ”;yield W

15、aitForSeconds (2); TypeText (); function Update () if(Input。GetKeyDown(KeyCode。Escape)screnbutton=true;if( Text = ”This is zcx first project! I can do it. ) Text = ”; TypeText (); if(Input.GetMouseButtonDown(0))Text = ;for (var c : char in Input.inputString) / Backspace Remove the last characterif (

16、c = b) if (guiText。text。Length != 0)guiText.text = guiText。text.Substring(0, guiText。text。Length - 1);/ End of entryelse if (c = n”) print (User entered his name: + guiText.text);/ Normal text input - just append to the endelse guiText.text += c;function OnGUI()if(screnbutton=true)if(GUI。Button(Rect

17、(Screen.width/230,Screen。height/230,60,50),scene1”))print(you click Scene 1”);Application.LoadLevel (1);screnbutton=false;else if(GUI.Button(Rect(Screen。width/230,Screen。height/2+30,60,50),scene2”)print(”you click Scene 2”);Application.LoadLevel (2);screnbutton=false;else if(GUI。Button(Rect(Screen。w

18、idth/230,Screen.height/2+90,60,50),”scene3))print(”you click Scene 3”);Application.LoadLevel (3);screnbutton=false;else if(GUI。Button(Rect(Screen。width/2-30,Screen。height/2+150,60,50),Quit))print(you click Quit);Application。Quit(); /GUI.Button (Rect (0, 0, 100, 20), ”Click Me”); GUI.Button (Rect (0,

19、 0, 100, 20), GUIContent (”Click me,This is the tooltip”); GUI。Label (Rect (0, 20, 100, 40), GUI.tooltip); allOptions = GUI.Toggle (Rect (40,40,150,20), allOptions, ”Edit All Options”); GUI。enabled = allOptions; extended1 = GUI。Toggle (Rect (60,60,130,20), extended1, Extended Option 1); extended2 =

20、GUI。Toggle (Rect (60,80,130,20), extended2, ”Extended Option 2); GUI.enabled = true; if (GUI。Button (Rect (40, 100, 150, 20), Ok) print (”user clicked ok”);GUI。BeginGroup (new Rect (Screen.width / 2 400, Screen.height/2-300,800,600));GUI.Box (new Rect (0,0,800,600), This box is now centered!-here yo

21、u would put your main menu);GUI。EndGroup (); GUI.Label (Rect(250,75,250,25),Please introduce your objec!”); GUI.Box (Rect(250,100,250,25),Text); function TypeText () for (var letter in word。ToCharArray()) /做一个循环,定义一个变量letter逐次等于word中的每一个字符 Text += letter;/把这些字赋值给Text if (sound)/控制声音,出现一个字,发一个声音 audi

22、o.PlayOneShot (sound); yield WaitForSeconds (letterPause); 主板游戏系列程序:CameraMoveRotate(第一视角界面场景自控程序)使用时点击鼠标右键可以自由转换视角.同时点击AWSD键可以控制前进后退,向左向右.C程序。using UnityEngine;using System.Collections;/ MouseLook rotates the transform based on the mouse delta./ Minimum and Maximum values can be used to constrain t

23、he possible rotation/ To make an FPS style character:/ - Create a capsule./ - Add a rigid body to the capsule/ Add the MouseLook script to the capsule。/ - Set the mouse look to use LookX. (You want to only turn character but not tilt it)/ - Add FPSWalker script to the capsule/ - Create a camera. Mak

24、e the camera a child of the capsule. Reset its transform。/ Add a MouseLook script to the camera./ Set the mouse look to use LookY。 (You want the camera to tilt up and down like a head. The character already turns.)AddComponentMenu(”Camera-Control/Mouse Look)public class CameraMoveRotate : MonoBehavi

25、our public enum RotationAxes MouseXAndY = 0, MouseX = 1, MouseY = 2 public RotationAxes axes = RotationAxes。MouseXAndY; public float sensitivityX = 15F; public float sensitivityY = 15F; public float minimumX = -360F; public float maximumX = 360F; public float minimumY = -60F; public float maximumY =

26、 60F; public float moveSpeed = 5。0F; float rotationX = 0F; float rotationY = 0F; Quaternion originalRotation; void Update () /鼠标控制的转向 if( !Input.GetMouseButton(1) ) return; else if (axes = RotationAxes。MouseXAndY) / Read the mouse input axis rotationX += Input。GetAxis(Mouse X) * sensitivityX; rotati

27、onY += Input.GetAxis(”Mouse Y”) sensitivityY; rotationX = ClampAngle (rotationX, minimumX, maximumX); rotationY = ClampAngle (rotationY, minimumY, maximumY); Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); Quaternion yQuaternion = Quaternion。AngleAxis (rotationY, Vector3。right

28、); transform。localRotation = originalRotation * xQuaternion yQuaternion; else if (axes = RotationAxes。MouseX) rotationX += Input.GetAxis(Mouse X”) sensitivityX; rotationX = ClampAngle (rotationX, minimumX, maximumX); Quaternion xQuaternion = Quaternion。AngleAxis (rotationX, Vector3.up); transform.lo

29、calRotation = originalRotation xQuaternion; else rotationY += Input。GetAxis(”Mouse Y) sensitivityY; rotationY = ClampAngle (rotationY, minimumY, maximumY); Quaternion yQuaternion = Quaternion。AngleAxis (rotationY, Vector3。right); transform.localRotation = originalRotation * yQuaternion; /键盘控制的运动 float x = Input.GetAxis(Horizontal) Time。deltaTime * moveSpeed; float z = Input。GetAxis(Vertical”) * Time。deltaTime moveSpeed; transform。Translate(x, 0, z); void Start () / Make the rigid body not change rotation

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1