I want to precisely control the position of an animation for mechanical designs. Think switches, diggers, etc.
The animations are created in 3ds Max and included in an FBX. I understand that there are two classes to control animations: Animation and Animator. Because Animation is the legacy system, I would like to use the Animator class, just in case the other one gets depreciated at some point.
But it seems it is not possible to set the time position when using an Animator. There is StartPlayback() and playbackTime, but that can only be used with an animation recorded in Unity itself, not an animation included in an FBX file.
So back to the Animation class, hoping that it won’t be ditched because that would be disastrous.
I have this code, but it gives a NullReferenceException because somehow normalizedTime doesn’t exist.
using UnityEngine;
using System.Collections;
public class AnimateTest : MonoBehaviour {
[Range(0.0f, 1.0f)]
public float slider;
private Animation animationComponent;
private AnimationClip animationClip;
// Use this for initialization
void Start () {
animationComponent = GetComponent<Animation>();
animationComponent.enabled = true;
animationClip = animationComponent.clip;
}
// Update is called once per frame
void Update () {
animationComponent[animationClip.name].normalizedTime = slider;
}
}
Any ideas?