zoukankan      html  css  js  c++  java
  • Unity 动画系统

    Legacy动画系统:Animation组件(旧)

    Mecanim动画系统:Animator组件(新)

    动画播放过程:

    //动画片段
    [System.Serializable]
    public class Anim
    {
        public AnimationClip idle;
        public AnimationClip runForward;
        public AnimationClip runBackward;
        public AnimationClip runRight;
        public AnimationClip runLeft;
    }
    
    public class PlayerCtrl : MonoBehaviour
    {   
        public Anim anim;
        public Animation _animation;
        
         void Start()
        {
            tr = GetComponent<Transform>();
            _animation = GetComponentInChildren<Animation>();
    
            //_animation.clip = anim.idle;
            //_animation.Play();
        }
    
       void Update()
        {
            h = Input.GetAxis("Horizontal");
            v = Input.GetAxis("Vertical");
    
            Vector3 moveDir = (Vector3.forward * v) + (Vector3.right * h);
            tr.Translate(moveDir.normalized * Time.deltaTime * moveSpeed, Space.Self);
            tr.Rotate(Vector3.up * Time.deltaTime * rotSpeed * Input.GetAxis("Mouse X"));
    
            if (v >= 0.1F)
            {
                _animation.CrossFade(anim.runForward.name, 0.3F);
            }
            else if (v <= -0.1F)
            {
                _animation.CrossFade(anim.runBackward.name, 0.3F);
            }
            else if (h >= 0.1F)
            {
                _animation.CrossFade(anim.runRight.name, 0.3F);
            }
            else if (h <= -0.1F)
            {
                _animation.CrossFade(anim.runLeft.name, 0.3F);
            }
            else
            {
                _animation.CrossFade(anim.idle.name, 0.3F);
            }
        }

    这个过程是很重要的,通过获取到的坐标的大小进行播放不同的动画,并且有着平稳的过度。

  • 相关阅读:
    053403
    053402
    053401
    053400
    053399
    053398
    053397
    053396
    053395
    第k小数
  • 原文地址:https://www.cnblogs.com/Optimism/p/10713487.html
Copyright © 2011-2022 走看看