1,首先设置好动画

 

unity blend tree unity blend tree exit time_右键

移除点击此处添加图片说明文字

我们在Run中设置混合1D动画

2,在Run的动画状态机中添加BlendTree,

选中Run,然后鼠标右键,点击Create new BlendTree in State.

 

unity blend tree unity blend tree exit time_Time_02

移除点击此处添加图片说明文字

3,进入BlendTree中,双击Run这个动画状态机之后就进入到了

 

unity blend tree unity blend tree exit time_右键_03

移除点击此处添加图片说明文字

这个就是Run的BlendTree。

4,在BlendTree中添加动画状态,有两种方法

   (1),选中BlendTree,鼠标右键选择AddMotion属性即可,AddBlendTree,是在此BlendTree上再次创建一个BlendTree

 

unity blend tree unity blend tree exit time_状态机_04

移除点击此处添加图片说明文字

   (2).选中BlendTree,在Inspector面板中点击 “+” 号,即可创建一个动画状态。

 

unity blend tree unity blend tree exit time_状态机_05

移除点击此处添加图片说明文字

5,动画状态创建号之后就可以在动画状态中添加动画了

 

unity blend tree unity blend tree exit time_unity blend tree_06

移除点击此处添加图片说明文字

,我在这里创建了三个动画状态,并在三个动画状态中添加了三个动画。分别为:RunLeft,Run,RunRight。

6,最重要的是选择动画的参数

 

unity blend tree unity blend tree exit time_unity blend tree_07

移除点击此处添加图片说明文字

而RunDirection的值是在

 

unity blend tree unity blend tree exit time_unity blend tree_08

移除点击此处添加图片说明文字

这里创建好的.

7,下面直接上代码

public class TurnTest : MonoBehaviour {
     public Animator m_animator;
void Start () {
         m_animator = GetComponent<Animator>();
     }

 void Update () {
         float h = Input.GetAxis("Horizontal"); //获取左右移动的参数
         float v = Input.GetAxis("Vertical"); //获取前后移动的参数
         print(h * h + v * v);
         m_animator.SetFloat("RunSpeed", h * h + v * v); //只要玩家点击前后左右的任意一个按键,RunSpeed的参数就不会为零。然后就开始移动
         m_animator.SetFloat("RunDirection", h, 0.1f, Time.deltaTime); //移动的值就是RunDirection.
}
 }

是不是很好理解...




1,首先设置好动画

 


unity blend tree unity blend tree exit time_右键

移除点击此处添加图片说明文字


我们在Run中设置混合1D动画

2,在Run的动画状态机中添加BlendTree,

选中Run,然后鼠标右键,点击Create new BlendTree in State.

 


unity blend tree unity blend tree exit time_Time_02

移除点击此处添加图片说明文字


3,进入BlendTree中,双击Run这个动画状态机之后就进入到了

 


unity blend tree unity blend tree exit time_右键_03

移除点击此处添加图片说明文字


这个就是Run的BlendTree。

4,在BlendTree中添加动画状态,有两种方法

   (1),选中BlendTree,鼠标右键选择AddMotion属性即可,AddBlendTree,是在此BlendTree上再次创建一个BlendTree

 


unity blend tree unity blend tree exit time_状态机_04

移除点击此处添加图片说明文字


   (2).选中BlendTree,在Inspector面板中点击 “+” 号,即可创建一个动画状态。

 


unity blend tree unity blend tree exit time_状态机_05

移除点击此处添加图片说明文字


5,动画状态创建号之后就可以在动画状态中添加动画了

 


unity blend tree unity blend tree exit time_unity blend tree_06

移除点击此处添加图片说明文字


,我在这里创建了三个动画状态,并在三个动画状态中添加了三个动画。分别为:RunLeft,Run,RunRight。

6,最重要的是选择动画的参数

 


unity blend tree unity blend tree exit time_unity blend tree_07

移除点击此处添加图片说明文字


而RunDirection的值是在

 


unity blend tree unity blend tree exit time_unity blend tree_08

移除点击此处添加图片说明文字


这里创建好的.

7,下面直接上代码

public class TurnTest : MonoBehaviour {
     public Animator m_animator;
void Start () {
         m_animator = GetComponent<Animator>();
     }

 void Update () {
         float h = Input.GetAxis("Horizontal"); //获取左右移动的参数
         float v = Input.GetAxis("Vertical"); //获取前后移动的参数
         print(h * h + v * v);
         m_animator.SetFloat("RunSpeed", h * h + v * v); //只要玩家点击前后左右的任意一个按键,RunSpeed的参数就不会为零。然后就开始移动
         m_animator.SetFloat("RunDirection", h, 0.1f, Time.deltaTime); //移动的值就是RunDirection.
}
 }

是不是很好理解...