![Unity3D常用腳本.doc_第1頁](http://file1.renrendoc.com/fileroot_temp2/2020-3/10/b4c4a888-148f-4974-b5e0-c129f0f7968b/b4c4a888-148f-4974-b5e0-c129f0f7968b1.gif)
![Unity3D常用腳本.doc_第2頁](http://file1.renrendoc.com/fileroot_temp2/2020-3/10/b4c4a888-148f-4974-b5e0-c129f0f7968b/b4c4a888-148f-4974-b5e0-c129f0f7968b2.gif)
![Unity3D常用腳本.doc_第3頁](http://file1.renrendoc.com/fileroot_temp2/2020-3/10/b4c4a888-148f-4974-b5e0-c129f0f7968b/b4c4a888-148f-4974-b5e0-c129f0f7968b3.gif)
![Unity3D常用腳本.doc_第4頁](http://file1.renrendoc.com/fileroot_temp2/2020-3/10/b4c4a888-148f-4974-b5e0-c129f0f7968b/b4c4a888-148f-4974-b5e0-c129f0f7968b4.gif)
![Unity3D常用腳本.doc_第5頁](http://file1.renrendoc.com/fileroot_temp2/2020-3/10/b4c4a888-148f-4974-b5e0-c129f0f7968b/b4c4a888-148f-4974-b5e0-c129f0f7968b5.gif)
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
場景轉(zhuǎn)換: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/2-380,Screen.height/2-190,60,50),Scene1) print(You click Scene1); Application.LoadLevel (1); screenbutton = false; else if(GUI.Button(Rect(Screen.width/2-380,Screen.height/2-130,60,50),Scene2) print(You click Scene2); Application.LoadLevel (2); screenbutton = false; else if( GUI.Button(Rect(Screen.width/2-375,Screen.height/2-0,50,50),Quit) print(You click Quit); Application.Quit(); 心得:場景轉(zhuǎn)換時(shí),這個(gè)程序貼在按鈕界面場景中。在Build Setting(導(dǎo)出)(在File下)菜單中加入所需場景。0為按鈕界面??梢詿o限增加場景。 else if(GUI.Button(Rect(Screen.width/2-380,Screen.height/2-130,60,50),Scene2) print(You click Scene2); Application.LoadLevel (2); screenbutton = false;復(fù)制此段程序并做修改。運(yùn)動控制鍵:上下左右var TankSpeed: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); transform.Rotate(Vector3.up * Time.deltaTime * -TankSpeed);else if(Input.GetKey(KeyCode.D) print(turn right); transform.Rotate(Vector3.up * Time.deltaTime * TankSpeed);需要放在第一視角的物體或者攝像機(jī)上。加天空背景:菜單欄Component下的Rendering下的Skybox。將他加在所需場景的攝像機(jī)上,選擇所需的天空。運(yùn)行時(shí)自然出現(xiàn)。各種按鈕匯總:鼠標(biāo)碰觸后顯示說明文字。function OnGUI () GUI.Button (Rect (0, 0, 100, 20), GUIContent (Click me, This is the tooltip); GUI.Label (Rect (0, 40, 100, 40), GUI.tooltip); 多項(xiàng)選擇,以上都選擇。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 = 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);鼠標(biāo)碰觸第一個(gè)按鈕有解釋,鼠標(biāo)碰觸第三個(gè)對話框有解釋。碰第二個(gè)沒有解釋。function 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); 半透明,說明性文字對話框。無選擇。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 ();滾動條,選擇按鈕。可以放多個(gè)按鈕并且節(jié)省位置。function Update () var scrollPosition = Vector2.zero;function OnGUI () scrollPosition = GUI.BeginScrollView (Rect (10,400,100,100),scrollPosition, Rect (0, 0, 220, 200);GUI.Button (Rect (0,0,100,20), Top-left);GUI.Button (Rect (120,0,100,20), Top-right);GUI.Button (Rect (0,180,100,20), Bottom-left);GUI.Button (Rect (120,180,100,20), Bottom-right);GUI.EndScrollView (); 循環(huán)的字幕。var letterPause = 0.2;/定義每個(gè)字出現(xiàn)的時(shí)間間隔 var sound : AudioClip;/打字機(jī)的聲音 private var word;/存儲你打字機(jī)效果想要輸出的字的變量 private var Text : String = My name is Ray Yang.Keep it in your heart!;/你希望打字機(jī)效果輸出的字 function Start () word = Text;/把你輸出的字先賦值給word Text = ;/把你要顯示的字先抹除,以便你可以在最初顯示的時(shí)候顯示為空,當(dāng)然你也可以加上其他字,讓他先顯示,打字機(jī)效果打的字會顯示在這個(gè)后面 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() /做一個(gè)循環(huán),定義一個(gè)變量letter逐次等于word中的每一個(gè)字符 Text += letter;/把這些字賦值給Text if (sound)/控制聲音,出現(xiàn)一個(gè)字,發(fā)一個(gè)聲音 audio.PlayOneShot (sound); yield WaitForSeconds (letterPause); function Update () if(Text = word) Text=; TypeText(); 有打字聲音的字幕循環(huán)。var screnbutton:boolean;var icon : Texture;var allOptions = true;var extended1 = true;var extended2 = true;var letterPause = 0.2;/定義每個(gè)字出現(xiàn)的時(shí)間間隔 var sound : AudioClip;/打字機(jī)的聲音 private var word;/存儲你打字機(jī)效果想要輸出的字的變量 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 WaitForSeconds (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 (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(Screen.width/2-30,Screen.height/2-30,60,50),scene1)print(you click Scene 1);Application.LoadLevel (1);screnbutton=false;else if(GUI.Button(Rect(Screen.width/2-30,Screen.height/2+30,60,50),scene2)print(you click Scene 2);Application.LoadLevel (2);screnbutton=false;else if(GUI.Button(Rect(Screen.width/2-30,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, 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 = 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 you 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() /做一個(gè)循環(huán),定義一個(gè)變量letter逐次等于word中的每一個(gè)字符 Text += letter;/把這些字賦值給Text if (sound)/控制聲音,出現(xiàn)一個(gè)字,發(fā)一個(gè)聲音 audio.PlayOneShot (sound); yield WaitForSeconds (letterPause); 主板游戲系列程序:CameraMoveRotate(第一視角界面場景自控程序)使用時(shí)點(diǎn)擊鼠標(biāo)右鍵可以自由轉(zhuǎn)換視角。同時(shí)點(diǎn)擊AWSD鍵可以控制前進(jìn)后退,向左向右。C#程序。using UnityEngine;using System.Collections;/ MouseLook rotates the transform based on the mouse delta./ Minimum and Maximum values can be used to constrain the 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. Make 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 : MonoBehaviour 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 = 60F;public float moveSpeed = 5.0F;float rotationX = 0F;float rotationY = 0F;Quaternion originalRotation;void Update ()/鼠標(biāo)控制的轉(zhuǎn)向if( !Input.GetMouseButton(1) )return;elseif (axes = RotationAxes.MouseXAndY)/ Read the mouse input axisrotationX += Input.GetAxis(Mouse X) * sensitivityX;rotationY += 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);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.localRotation = originalRotation * xQuaternion;elserotationY += Input.GetAxis(Mouse Y) * sensitivityY;rotationY = ClampAngle (rotationY, minimumY, maximumY);Quaternion yQuaternion = Quaternion.AngleAxis (-rotationY, Vector3.right);transform.localRotation = originalRotation * yQuaternion; /鍵盤控制的運(yùn)動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 rotationif (rigidbody)rigidbody.freezeRotation = true;originalRotation = transform.localRotation;public static float ClampAngle (float angle, float min, float max)if (angle 360F)angle -= 360F;return Mathf.Clamp (angle, min, max);Unity3d閃爍燈光腳本也可以用unity3d做舞廳效果。把腳本扔給燈光就可以了。1. using UnityEngine;2. using System.Collections;3. RequireComponent( typeof( Light ) )4. public class flickeringLight : MonoBehaviour5. 6. / Flickering Styles7. public enum flickerinLightStyles CampFire = 0, Fluorescent = 1 ;8. public flickerinLightStyles flickeringLightStyle = flickerinLightStyles.CampFire;9. / Campfire Methods10. public enum campfireMethods Intensity = 0, Range = 1, Both = 2 ;11. public campfireMethods campfireMethod = campfireMethods.Intensity;12. / Intensity Styles13. public enum campfireIntesityStyles Sine = 0, Random = 1 ;14. public campfireIntesityStyles campfireIntesityStyle = campfireIntesityStyles.Random;15. / Range Styles16. public enum campfireRangeStyles Sine = 0, Random = 1 ;17. public campfireRangeStyles campfireRangeStyle = campfireRangeStyles.Random;18. / Base Intensity Value19. public float CampfireIntensityBaseValue = 0.5f;20. / Intensity Flickering Power21. public float CampfireIntensityFlickerValue = 0.1f;22. / Base Range Value23. public float CampfireRangeBaseValue = 10.0f;24. / Range Flickering Power25. public float CampfireRangeFlickerValue = 2.0f;26. 27. / If Style is Sine28. private float CampfireSineCycleIntensity = 0.0f;29. private float CampfireSineCycleRange = 0.0f;30. / Glow Speeds31. public float CampfireSineCycleIntensitySpeed = 5.0f;32. public float CampfireSineCycleRangeSpeed = 5.0f;33. public float FluorescentFlickerMin = 0.4f;34. public float FluorescentFlickerMax = 0.5f;35. public float FluorescentFlicerPercent = 0.95f;36. / NOT IMPLEMENTED YET !37. public bool FluorescentFlickerPlaySound = false;38. public AudioClip FluorescentFlickerAudioClip;39. / -40.41.42. / Use this for initialization43. void Start () 44. 45. 46. 47. / Update is called once per frame48. void Update () 49. switch( flickeringLightStyle )50. 51. / If Flickering Style is Campfire52. case flickerinLightStyles.CampFire:53. / If campfire method is Intesity OR Both54. if( campfireMethod = campfireMethods.Intensity | campfireMethod = campfireMethods.Both )55. 56. / If Intensity style is Sine57. if( campfireIntesityStyle = campfireIntesityStyles.Sine )58. 59. / Cycle the Campfire angle60. CampfireSineCycleIntensity += CampfireSineCycleIntensitySpeed;61. if( CampfireSineCycleIntensity 360.0f ) CampfireSineCycleIntensity = 0.0f;62. / Base + Values63. ensity = CampfireIntensityBaseValue + ( ( Mathf.Sin( CampfireSineCycleIntensity * Mathf.Deg2Rad ) * ( CampfireIntensi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 職工困難補(bǔ)助申請書
- 建筑機(jī)械設(shè)備項(xiàng)目可行性研究報(bào)告
- 2025年自動空氣洗瓶機(jī)項(xiàng)目投資可行性研究分析報(bào)告-20241226-194854
- 中國哈密瓜卷心酥項(xiàng)目投資可行性研究報(bào)告
- 醫(yī)學(xué)病理生理題庫
- 短視頻創(chuàng)作技巧教育類視頻的吸引力打造
- 成都市金牛區(qū)2024年七年級《英語》上冊期末試卷與參考答案
- 長沙市長沙縣2022年七年級《語文》下冊期末試卷與參考答案
- 新版人教PEP版三年級下冊英語課件 Unit 4 Part A 第2課時(shí)
- 2025年山東青島望海國際酒店管理有限責(zé)任公司招聘筆試參考題庫附帶答案詳解
- 2024年01月江西2024年江西銀行贛州分行招考筆試歷年參考題庫附帶答案詳解
- 初三數(shù)學(xué)一元二次方程應(yīng)用題附答案
- 教職工安全管理培訓(xùn)
- 云南省曲靖市羅平縣2024-2025學(xué)年高二上學(xué)期期末地理試題( 含答案)
- 2025年春新人教PEP版英語三年級下冊課件 Unit 1 Part C 第8課時(shí) Reading time
- 中國糖尿病防治指南(2024版)要點(diǎn)解讀
- Unit 1 Nice boys and girls【知識精研】-一年級英語下學(xué)期(人教PEP版一起)
- 《口腔科學(xué)緒論》課件
- 《消防檢查指導(dǎo)手冊》(2024版)
- 2024年萍鄉(xiāng)衛(wèi)生職業(yè)學(xué)院單招職業(yè)技能測試題庫標(biāo)準(zhǔn)卷
- 粵教粵科版三年級下冊科學(xué)全冊課時(shí)練(同步練習(xí))
評論
0/150
提交評論