好想骂人啊,终于解决了
问题
我使用blendtree让角色进行跑,向左转,向右转,跳跃的的功能,但角色其他动画播放正常,只要转向就在原地不动了
原因:动画播放完了就不动了,设置下loop属性就行了。
使用blendtree
1 动画如果只在原地运动,可以给动画添加运动曲线,(curves,在animation视窗中)然后给忽角色添加运动代码
OnAnimatorMove函数中
void OnAnimatorMove()
{
Animator animator = GetComponent<Animator>();
if (animator)
{
Vector3 newposition = transform.position;
newposition.z += animator.GetFloat("run") * Time.deltaTime;
transform.position = newposition;
}
}
2 创建控制器controller,给控制器添加动画,添加blendtree,如果想控制动画运动可以给controller添加变量通过condition条件控制角色运动
添加代码
public class blendTree1 : MonoBehaviour {
Animator animator1;
public float speed1 = 0.08f;
// Use this for initialization
void Start () {
animator1 = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (animator1)
{
AnimatorStateInfo statInfo = animator1.GetCurrentAnimatorStateInfo(0);
if (statInfo.IsName("Base Layer.Run"))
{
if (Input.GetKey(KeyCode.A))
{
animator1.SetBool("jump", true);
}
}
else
{
animator1.SetBool("jump", false);
}
float horizontal = Input.GetAxis("Horizontal");
animator1.SetFloat("speed", horizontal, speed1, Time.deltaTime);
}
}
}