unity3d easytouch教程

http://www.taikr.com/group/6/thread/1987

说一说easytouch的简单使用方法,和移动平台上的rpg游戏一样,我们肯定也不陌生,我们经常玩游戏的时候用的都是虚拟摇杆来控制人物的行动和走动,我就简单说下unity3d easytouch教程中的easytouch怎么使用的。

一、效果图

unity3d easytouch教程

unity3d easytouch教程

感觉很酷有木有!接下来就看一下创建的过程吧!

二、操作步骤

1.官方文档上的步骤

Quick Start (C#)

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

unity3d easytouch教程

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.

unity3d easytouch教程

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. // Unsubscribe 

  5. void OnDisable(){ 

  6. EasyTouch.On_TouchStart -= On_TouchStart; 

  7. // Unsubscribe 

  8. void OnDestroy(){ 

  9. EasyTouch.On_TouchStart -= On_TouchStart; 

  10. // Touch start event 

  11. publicvoid On_TouchStart(Gesture gesture){ 

  12. Debug.Log("Touch in " + gesture.position); 

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

2.翻译一下以上的步骤

  1.import“EasyTouch”资源包

        2.创建空物体,命名为EasyTouch(当然你也可以改成其他名字)

        3.添加EasyTouch.cs脚本在刚刚创建的空物体(EasyTouch)上

4.选择改物体但不要将BroadcastMessages勾选

5.创建一个新的C#脚本,命名MyFirstTouch

6.添加这些方法

7.再创建一个空物体,命名为Receiver

8.将MyFirstTouch脚本添加到空物体Receiver上

9.运行并且点击遥感,会发现控制台打印了当前按下的坐标

3.根据官方的这些提示,自己来做一个属于自己的人物遥感控制

   1.导入EasyTouch3资源包

2.做好前期准备,包括人物模型、地形的创建

3.添加JoyStick实例:Hedgehog Team->Easy Touch->Extensions->Add a new Joystick。此时就会在左下角创建了虚拟遥感的实例。

        4.设置遥感的相关参数

5.创建脚本MoveController.cs用来接收遥感事件控制角色的移动

  1. using UnityEngine; 

  2. using System.Collections; 

  3.  

  4. publicclass 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.     } 

几个函数的执行顺序:


unity3d easytouch教程

6.效果图

unity3d easytouch教程


7.创建点击按钮

点击HedgehogTeam->EasyTouch->Extensions->Create a new Button,会在屏幕右下角创建一个button

unity3d easytouch教程


如何让有下角的按钮点击能做出我们想要的效果呢?


jump方法:

unity3d easytouch教程

原文地址:https://www.cnblogs.com/nafio/p/9137496.html