Unity 中EasyTouch和播放动画的结合
2016-04-11 本文已影响1118人
药药耀耀
首先 我们引入Easy Touch插件,在Joystick X to 把我们的人物拖进去 这里是指摇杆的X轴方向控制人物物体的X轴运动
同理 下面的是摇杆Y轴控制Z轴方向


加入场景的中的摇杆是这样的 摇杆样式图片可以自己更改

然后我们在人物的Animatior组件中添加状态机 ,同时我们设置事件为float类型的参数


为我们的人物添加一个名为Player Move的脚本
注意脚本中的Speed参数是使融合树中的阈值

using UnityEngine;
using System.Collections;
public class PlayerMove : MonoBehaviour {
Animator player;
float Speed=1.41f;
void Awake()
{
//获取player人物的动画组件
player = GameObject.Find("Player").GetComponent<Animator>();
}
void Start () {
//EasyTouch 的订阅事件
EasyJoystick.On_JoystickMove += Move;
//EasyTouch 的订阅事件
EasyJoystick.On_JoystickMoveEnd += MoveEnd;
}
void Move(MovingJoystick move)
{
//动画控制器中的Speed值设为摇杆到圆心的Value值得百分比乘上动画融合树的阈值
float speed = Vector2.Distance(move.joystickValue, Vector2.zero)*Sspeed;
player.SetFloat("SpeedX", speed);
player.transform.rotation = Quaternion.AngleAxis(move.Axis2Angle(), Vector3.up);
}
void MoveEnd(MovingJoystick move)
{
float speed = Vector2.Distance(move.joystickValue, Vector2.zero)*Sspeed;
player.SetFloat("SpeedX", speed);
}
}
注意状态机中的事件的参数 必须小于1 同时调试 使人物的动作变得流畅

