zoukankan      html  css  js  c++  java
  • 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);
            }
    	}
    }
    

      

     

  • 相关阅读:
    树莓派安装parrot linux记录
    Arch linux(UEFI+GPT)安装及后续优化教程
    VS部分安全函数用法
    C语言博客作业06--结构体&文件
    C语言博客作业05--指针
    C语言博客作业04--数组
    C语言博客作业03--函数
    C语言博客作业02--循环结构
    DS博客作业08--课程总结
    DS博客作业07--查找
  • 原文地址:https://www.cnblogs.com/lv-sally/p/4519134.html
Copyright © 2011-2022 走看看