目的:
代码中经常需要动态替换AnimatorController动画剪辑即:AnimationClip,这里先提供替换的代码:
// 要替换Clip
public AnimationClip clip;
private Animator animator;
void Awake()
{
animator= GetComponent<Animator>();
}
void Start () {
AnimatorOverrideController overrideController = new AnimatorOverrideController();
overrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
overrideController["testCip"] = clip;
animator.runtimeAnimatorController = overrideController;
}
注意事项: overrideController["testClip"] = clip;里面的testClip不是状态机里面状态名,而是实际要替的clip的名称。