I create a simple animation and an override controller for it with code.
//AnimationScript.cs
public Vector3 direction;
public float distance;
void Start()
{
direction = direction.normalized;
Vector3 posA = transform.position;
Vector3 posB = posA + (direction * distance);
AnimationClip clip = new AnimationClip();
AnimationCurve curve = AnimationCurve.Linear(0.0f, posA.y, 1.0f, posB.y);
clip.SetCurve("", typeof(Transform), "localPosition.y", curve);
Animator anim = GetComponent<Animator>();
AnimatorOverrideController animatorOverrideController = new AnimatorOverrideController(anim.runtimeAnimatorController);
// "loop" is the name of clip not name of state
animatorOverrideController["loop"] = clip;
anim.runtimeAnimatorController = animatorOverrideController;
}
When I preview animation it works perfect, but when I export and play it, it does not start but camera motion works. What is the reason for that and how do I correct it?
Here are my object settings and controller: