資源描述:
《unity3d游戲開發(fā)之IOS自定義游戲搖桿與飛機平滑的移動(》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、移動開發(fā)游戲中使用到的觸摸游戲搖桿在iPhone上是非常普遍的,畢竟是全觸摸屏手機,今天MOMO通過一個小例子和大家討論unity3D中如何自定義一個漂亮的全觸摸游戲搖桿。??出自狗刨學(xué)習(xí)網(wǎng)??????????值得高興的是,unity3d?游戲引擎的標準資源中已經(jīng)幫助我們封裝了一個游戲搖桿腳本,所以實現(xiàn)部分的代碼可以完全借助它的,具體調(diào)用需要我們自己來。????Joystick.js是官方提供的腳本,具體代碼如下,有興趣的朋友可以仔細研究研究,MOMO就不多說啦。哇咔咔~1.////////////////////////////////
2、//////////////////////////////2.//Joystick.js3.//PenelopeiPhoneTutorial4.//5.//Joystickcreatesamovablejoystick(viaGUITexture)that6.//handlestouchinput,taps,andphases.Deadzonescancontrol7.//wherethejoystickinputgetspickedupandcanbenormalized.8.//9.//Optionally,youcanenable
3、thetouchPadpropertyfromtheeditor10.//totreatthisJoystickasaTouchPad.ATouchPadallowsthefinger11.//totouchdownatanypointandittracksthemovementrelatively12.//withoutmovingthegraphic13.//////////////////////////////////////////////////////////////14.??15.@scriptRequireCompone
4、nt(GUITexture)16.??17.//AsimpleclassforboundinghowfartheGUITexturewillmove18.classBoundary19.{20.??varmin:Vector2=Vector2.zero;21.??varmax:Vector2=Vector2.zero;22.}23.??24.staticprivatevarjoysticks:Joystick[];??????????????//Astaticcollectionofalljoysticks25.staticprivate
5、varenumeratedJoysticks:boolean=false;26.staticprivatevartapTimeDelta:float=0.3;??????????//Timeallowedbetweentaps1.??2.vartouchPad:boolean;????????????????????????//IsthisaTouchPad?3.vartouchZone:Rect;4.vardeadZone:Vector2=Vector2.zero;????????????????//Controlwhenpositio
6、nisoutput5.varnormalize:boolean=false;????????????????????//Normalizeoutputafterthedead-zone?6.varposition:Vector2;????????????????????????//[-1,1]inx,y7.vartapCount:int;??????????????????????????????//Currenttapcount8.??9.privatevarlastFingerId=-1;??????????????????????/
7、/Fingerlastusedforthisjoystick10.privatevartapTimeWindow:float;??????????????????//Howmuchtimethereisleftforataptooccur11.privatevarfingerDownPos:Vector2;12.privatevarfingerDownTime:float;13.privatevarfirstDeltaTime:float=0.5;14.??15.privatevargui:GUITexture;?????????????
8、?????????//Joystickgraphic16.privatevardefaultRect:Rect;??????????????????????//Defaultposition/