欢迎来到天天文库
浏览记录
ID:47068281
大小:325.00 KB
页数:12页
时间:2019-07-14
《unity3d游戏开发之IOS自定义游戏摇杆与飞机平滑的移动(》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、移动开发游戏中使用到的触摸游戏摇杆在iPhone上是非常普遍的,毕竟是全触摸屏手机,今天MOMO通过一个小例子和大家讨论unity3D中如何自定义一个漂亮的全触摸游戏摇杆。 出自狗刨学习网 值得高兴的是,unity3d 游戏引擎的标准资源中已经帮助我们封装了一个游戏摇杆脚本,所以实现部分的代码可以完全借助它的,具体调用需要我们自己来。 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/
此文档下载收益归作者所有