1.。新建分层,将两个AnimationClip放到不同分层中。
点击右上角设置,调节weight的值(该层动画融合的比重),将此animatorcontroller拖入Animator中,勾选自动运行,运行项目即可同时播放这两个动画。
思路: 通过AnimatorOverrideController类,动态覆盖状态机中的动画片段
原状态机中有两个动画片段,名字为“1”、“2”,分别在两个分层下
将下面的代码挂载到带动画的物体上
public AnimationClip anima1; public AnimationClip anima2; private Animator animator; AnimatorOverrideController overrideController; void Start () { animator = GetComponent<Animator>(); RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController; overrideController = new AnimatorOverrideController(); overrideController.runtimeAnimatorController = runtimeAnimatorController; overrideController["1"] = anima1; overrideController["2"] = anima2; } // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.A)) { animator.runtimeAnimatorController = overrideController; } }
拖入想更换的动画
动画“1”为向右移动,“2”为旋转,“3” 为向上移动,“4” 为放大。
文章来源: https://blog.csdn.net/weixin_39562801/article/details/88873511