unity3d中高級(jí)手冊(cè)01基本3-7使用腳本_第1頁(yè)
unity3d中高級(jí)手冊(cè)01基本3-7使用腳本_第2頁(yè)
unity3d中高級(jí)手冊(cè)01基本3-7使用腳本_第3頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、UsingScripts Unity Manual User Guide Working ssetsUsingUnity 手冊(cè)- 用戶指南 -與資產(chǎn)合作-使ThisisaroductiononhowtocreateandutilizescriptsinaUsingScripts Unity Manual User Guide Working ssetsUsingUnity 手冊(cè)- 用戶指南 -與資產(chǎn)合作-使Thisisaroductiononhowtocreateandutilizescriptsinaproject.FordetailedinformationaboutScripting A

2、PI, please view the Scripting Reference. For detailed information scripting,pleaseviewtheCreatingGameplaypageofthisreatinggameplayAPI 的詳細(xì)信息,請(qǐng)查這是一個(gè)小的介紹如何在一個(gè)項(xiàng)目里建立和使。關(guān)玩家的詳細(xì)信息,請(qǐng)查看本手冊(cè)的建Scripting inside Unity is done by writing ehaviourscriptsinJavaScript,BooorC#.Youcanuseoneall scripting languages in a s

3、ingle project, there isno penalty for using none.Unlesss edallthescriptinglesareinUnity JavaScript, Boo 或 C#之內(nèi)。你可以使用一個(gè)或所有簡(jiǎn)本的完成通過編寫簡(jiǎn)單行例子是 JavaScript 的言在一個(gè)獨(dú)立的項(xiàng)目中,使用多于一個(gè)沒有損失。除非另有說明,所有Creatingnew scripts UnlikeotherassetslikeMeshesorTextures,ScriptfilescanbecreatedfromwithinUnity.Tocreateascript, open t

4、he Assets-Create-JavaScript (or Assets-Create-C Sharp Script or Assets-Create-Script)fromtheenu.ThiswillcreateanewscriptcalledNewBehaviourScriptandplaceselectedfolderin ProjectView.IfnofolderectedinProjectView,thescriptwillbecreatedatthe和其它資產(chǎn)不同,像網(wǎng)格或紋理文件可以 被建立。,從主菜單打Assets-Create-JavaScript(或 Assets-

5、Create-C Sharp Scrip 或 Assets-Create-Boo Script)建立一個(gè)稱為 NewBehaviourScript 并放置它在項(xiàng)目視圖里選擇的文件夾里。如果在項(xiàng)目視圖里沒有文件選取將被建立在根Youcaneditthescriptbydouble-clickingonheProjectView.Thiswillitron,thescripteditorUnity.YoudoallyourscriptinginanexternaltexteditorlkeUnitron,andnotinYoucaneditthescriptbydouble-clickingonh

6、eProjectView.Thiswillitron,thescripteditorUnity.YoudoallyourscriptinginanexternaltexteditorlkeUnitron,andnotinUnitydirectly.Tosetthescript editor, change the drop-down item in Unity-External Script 你可以在項(xiàng)目視圖里通過上雙擊編輯它。這將啟動(dòng) Unitron,Unity 編輯器。在外部文本編輯器里理所有像 Unitron 一樣,但不如在 Unity 里直接。設(shè)置默認(rèn)編輯器,Unity-Externa

7、l Script editor 里(windows 上是 Eidt-External editor)These are the contents of a new, empty behaviour script: 這些是新的內(nèi)容:Anew,emptyscriptdoesnotdoalotonitsown,soletsaddsomefunctionality.Changethescripttoread一個(gè)新的,空When executed, this code will o Worldto theconsole.But there is tcausesthecodetoexecutedyet.W

8、ehavetoattachthescripttoanactive heScenebeforeitwillbe當(dāng)執(zhí)行,這個(gè)代碼將打印World到一個(gè)活動(dòng)的 GameObjectAttachingscriptstoobjects Save theabove script and create a newThis will create a new GameObject called he Scene by selecting GameObject-Create Other-hecurrent保存上面并建立一個(gè)新的對(duì)象在場(chǎng)景里通過選取 GameObject-Other-Cube。這將建立一個(gè)的物體稱

9、為Cube”在當(dāng)前場(chǎng)景里functionUpdate()pr o functionUpdate()NowdragthescriptfromtheProjectViewtotheCubeheSceneorHierarchyView,itdoesntNowdragthescriptfromtheProjectViewtotheCubeheSceneorHierarchyView,itdoesntmatter).csoselecttheCubeandchooseComponent-Scripts-New Behaviour Script.Eitherofthesewillattachthescrip

10、ttotheCube.Everyscriptyoucreatewillhe Component-. Ifhavechanged the name of your script, you tname現(xiàn)在從項(xiàng)目視圖里拖到這個(gè)立方體(Cube)(在場(chǎng)景里或?qū)哟我晥D里,這無關(guān)緊要)。你也可以選取這個(gè) Cube 并選擇 Component-Scripts-New Behaviour ScriptCube建立的每將顯示在 Component-Scripts 菜單里。如果你已經(jīng)修改了的名稱,你將代替名稱IfyouselecttheCubeandlookattheInspector,youwillbeen t

11、thescriptisnowvisible.Thismeanss如果你選取里 Cube 是現(xiàn)在可見。這意味著它已經(jīng)被附加了PressPlaytotestyourcreation.Youshouldseethetextbuttons.Exitplaymodewhenyouseeo World appear beside the 按按鈕去測(cè)試你的創(chuàng)造。你應(yīng)該看到PressPlaytotestyourcreation.Youshouldseethetextbuttons.Exitplaymodewhenyouseeo World appear beside the 按按鈕去測(cè)試你的創(chuàng)造。你應(yīng)該看到o

12、 World文本顯Play/Pause/Step 按鈕旁邊 (2.5 版的里,顯示在底部狀態(tài)欄)模式Manipulatingtheobject A()s ementcanbeveryhandywhendebuggingyourscript,butitdoesnotmanipulatetheitisattachedto.Letschangethescripttoaddsome一個(gè) pr ()語(yǔ)句可以非常便利的當(dāng)調(diào)試你時(shí),但它不能操作被附屬于的 物體)。讓If youre new to scripting, its okay if this looks confusing. These are t

13、he important concepts to functionUpdate()isacontainerfortUnityexecutesmultipletimespersecondper frame). function Update () 是 Unity 多個(gè)時(shí)間每秒鐘執(zhí)行代碼的容器(一次每幀)transform is a reference to the GameObjects Transform Component. Transform 是一個(gè)對(duì)象物。e() is a function器he Transform Component. e()是在變換組件里的功functionUpdat

14、e()e(0, ime, Thenumbersin-nthecommasrepresentthedegreesofro ionaroundeachaxisofspaceXYandZ. 在逗號(hào)之間的數(shù)字表示環(huán)繞每個(gè)3D空間空間軸:x,yz 的旋轉(zhuǎn)的角度imeisamemberoftheTimet evens out movement over cond, so cubewillro eatthesamespeedThenumbersin-nthecommasrepresentthedegreesofro ionaroundeachaxisofspaceXYandZ. 在逗號(hào)之間的數(shù)字表示環(huán)繞每個(gè)

15、3D空間空間軸:x,yz 的旋轉(zhuǎn)的角度imeisamemberoftheTimet evens out movement over cond, so cubewillro eatthesamespeednomatterhowmanyframespersecondyourmachineisTherefore,5*imemeans5degreesperime 是 Time 類的一個(gè)成員,使每秒移動(dòng)平坦,因此這個(gè)Cube 器的每秒的多少幀被繪制。所以,5 * ime 意味著5 度。llind,wecanreadthiscodeaseveryframe,ro ethisGameObjectsTrans

16、formcomponentsmall amount titwillequalfivedegreesaroundtheYaxiseach可以閱讀這個(gè)代碼作為“每一個(gè)幀,旋轉(zhuǎn)這個(gè) GameObject 的變換組件一個(gè)小的數(shù)量因此所有在這一點(diǎn)將等5度環(huán)YYoucanslotsofdifferentComponentsthesamewayaswesed transform already. You have addComponentstotheGameObjectusingthe.AlltheComponentsyoucaneasilyarelistedunderVariablesontheGameO

17、bjectScriptingReference了 transform 的一樣方法。你必須添加組件已GameObject 被在 For more information about the relationship n GameObjects, Scripts, and Components, please ahead to the GameObjects page or Using Components page of this GameObjects, Scripts Components Using Components 信息,請(qǐng)?zhí)角懊娴?GameObjects 頁(yè)或本手冊(cè)erofVar

18、iables Ourscriptsofarwillalwaysro etheCube5degreeseachsecond.Wemightwantittoro eanumberofdegreespersecond.Wecouldchangethenumberandsave,butthenwehavetowaitforthetoledandwehavetolaymodebeforeweseetheresults.ThereisamuchfasterwayWecanexperimentwiththespeedofro ioninreal-timeduringPlaymode,anditseasyto

19、的到目前為止將總每秒選擇 Cube 5 度也許想要它每秒選擇不同數(shù)量的角度可以改變數(shù)據(jù)并保存它,須等被從新編譯以須進(jìn)模式看到結(jié)果之前。有一個(gè)非常快速方法去做它。在實(shí)模式過程中Insteadofothee() function, we will declare a speed variable and theChangethescripttothefollowingcodeandsave替代在e()函數(shù)輸入 定義一個(gè) 變量并在函數(shù)里使用它。修Now select the Cube and look at the Inspector. Notice how our speed variable 現(xiàn)

20、在,選取這個(gè) Cube 的 speed 變量如何顯示Now select the Cube and look at the Inspector. Notice how our speed variable 現(xiàn)在,選取這個(gè) Cube 的 speed 變量如何顯示ThisvariablecannowbemodifiedheInspector,justlikerenamingahe file explorer. Select press Return and change the value. You soright-oroption-clickonthevalueanddragthemouseup

21、down.Youcanchangethevariableatanytime,evenwhilethegameis并修改它的值。你也可以恰當(dāng)?shù)狞c(diǎn)擊選項(xiàng)并左右拖動(dòng)鼠標(biāo)(修改值。你可以在任何時(shí)間更改變量,甚至當(dāng)在HitPlayandtrymodifyingthespeedvalue.TheCubesonspeedwillchangeinstantly.WhenyouPlaymode,youlltyourchangesarerevertedbacktotheirvaluebeforeenteringPlaymode.Thisyoucanplay,adjust,andexperimenttofindthebestvalue,thentvalue擊按鈕并嘗試修改 speed 變量的值。這個(gè) Cube 的旋轉(zhuǎn)速度的更改回復(fù)到進(jìn)模式之前的它們值。這個(gè)方法你可、調(diào)整以及實(shí)驗(yàn)去找打最優(yōu)的值,然后應(yīng)用不varspeed =functionUpdate()e(0, ime, Using this method of changing a variables he Inspectortyoucanre-useonescriptonobjects, each different v

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論