- Home /
Question by
Bongmo · Apr 14, 2019 at 12:02 AM ·
animatoranimationclipanimationstate
How can I add a motion clip to the animator state by script?
You can see, that I added a new state with the name "StateEmpty" in the Animator. In the bottom image you see the motion slot. How can I add a motion clip to the animator state "StateEmpty" by script?
What I've programmed so far:
using UnityEngine;
public class Testing : MonoBehaviour
{
public AnimationClip animationClip;
Animator animator;
AnimatorOverrideController animatorOverrideController;
public void Start()
{
animator = GetComponent<Animator>();
animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
animator.runtimeAnimatorController = animatorOverrideController;
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// https://docs.unity3d.com/ScriptReference/AnimatorOverrideController.html
//animatorOverrideController["shot"] = animationClip;
// ... ?
}
}
}
I really don't know how to access this slot.
untitled.png
(42.2 kB)
Comment