标签:end not iss 实现 方法 == size 素材 步骤
对于移动平台上的RPG类的游戏,我们常用虚拟摇杆来控制人物角色的行走和一些行为,相信我们对它并不陌生,之前尝试了EasyTouch2.5,发现并没有最新版的3.1好用,2.5版本的对于自适应没有做的很好,而最新版的已经解决了这一问题。当然unity也自带了摇杆Joystick,用起来也简单,但存在不少局限,不会满足普通mmo游戏的需求,比如指定显示区域或者是更改一些素材等等,而这些EasyTouch插件都已经帮你实现,不得不佩服插件的原作者,能做出这么炫酷好用的插件,当然这估计是老外开发的,关于插件的下载,你可以在AssetStore上购买,当然也可以使用free版。
感觉很酷有木有!接下来就看一下创建的过程吧!
1-Import EasyTouch Package.
2-Create an empty gameObject, and name it EasyTouch.(You can choose another name)
Step 1 & 2 can be replace by the option menu
3-Add the EasyTouch.cs script on the EasyTouch gameObject that you just created.
4-Select the EasyTouch gameobject, and verifies that Broadcast messages is set to FALSE in the inspector.
5-Create a new C# script MyFirstTouch
6-Add these methods
1 // Subscribe to events 2 void OnEnable(){ 3 EasyTouch.On_TouchStart += On_TouchStart; 4 } 5 // Unsubscribe 6 void OnDisable(){ 7 EasyTouch.On_TouchStart -= On_TouchStart; 8 } 9 // Unsubscribe 10 void OnDestroy(){ 11 EasyTouch.On_TouchStart -= On_TouchStart; 12 } 13 // Touch start event 14 public void On_TouchStart(Gesture gesture){ 15 Debug.Log( "Touch in " + gesture.position); 16 }
7-Create an empty gameObject, and name it Receiver.
8- Add MyFirstTouch script to the gameObject Receiver.
9- Run it in editor, and click on the screen
1.import“EasyTouch”资源包
2.创建空物体,命名为EasyTouch(当然你也可以改成其他名字)
3.添加EasyTouch.cs脚本在刚刚创建的空物体(EasyTouch)上
4.选择改物体但不要将BroadcastMessages勾选
5.创建一个新的C#脚本,命名MyFirstTouch
6.添加这些方法
7.再创建一个空物体,命名为Receiver
8.将MyFirstTouch脚本添加到空物体Receiver上
9.运行并且点击遥感,会发现控制台打印了当前按下的坐标
1 using UnityEngine; 2 using System.Collections; 3 4 public class MoveController : MonoBehaviour { 5 6 void OnEnable() 7 { 8 EasyJoystick.On_JoystickMove += OnJoystickMove; 9 EasyJoystick.On_JoystickMoveEnd += OnJoystickMoveEnd; 10 } 11 12 13 //移动摇杆结束 14 void OnJoystickMoveEnd(MovingJoystick move) 15 { 16 //停止时,角色恢复idle 17 if (move.joystickName == "MoveJoystick") 18 { 19 animation.CrossFade("idle"); 20 } 21 } 22 23 24 //移动摇杆中 25 void OnJoystickMove(MovingJoystick move) 26 { 27 if (move.joystickName != "MoveJoystick") 28 { 29 return; 30 } 31 32 //获取摇杆中心偏移的坐标 33 float joyPositionX = move.joystickAxis.x; 34 float joyPositionY = move.joystickAxis.y; 35 36 37 if (joyPositionY != 0 || joyPositionX != 0) 38 { 39 //设置角色的朝向(朝向当前坐标+摇杆偏移量) 40 transform.LookAt(new Vector3(transform.position.x + joyPositionX, transform.position.y, transform.position.z + joyPositionY)); 41 //移动玩家的位置(按朝向位置移动) 42 transform.Translate(Vector3.forward * Time.deltaTime * 5); 43 //播放奔跑动画 44 animation.CrossFade("run"); 45 } 46 } 47 }
标签:end not iss 实现 方法 == size 素材 步骤
原文地址:http://www.cnblogs.com/AaronBlogs/p/7040100.html