unity animator BlendTree1

好想骂人啊,终于解决了

问题

我使用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);
        }
	}
}

  

 

 

转载于:https://www.cnblogs.com/lv-sally/p/4519134.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值