- Home /
How does one make use of Animator.StartPlayback()?
The documentation for Animator.StartPlayback() says "...Note that time will not automatically progress here, you have to manipulate it explicitly from playbackTime.."
I'm trying to learn about this because I read somewhere that this can be used to control an animation's frames. When I try to implement this on my code I get a warning saying "Can't playback from recorder, no recorded data found".
How does one make use of this function? Maybe I'm using it for the wrong reasons? This is the code I'm using:
using UnityEngine;
using System.Collections;
public class NumCard : MonoBehaviour
{
private Animator animator;
public void Init()
{
//Debug.Log("initializing: " + transform.name);
animator = transform.GetComponent<Animator>();
animator.StartPlayback();
animator.playbackTime = 2f;
Debug.Log("time: " + animator.playbackTime);
}
}
Answer by Elecman · Jul 14, 2015 at 02:24 AM
As far as I understand, StartPlayback() can not be used to play an animation included in the model. You have to record the animation at runtime in Unity itself using StartRecording(), then you can play that back. The documentation is not very clear on this.
Edit: Here is a working version which makes use of Animation instead of Animator:
using UnityEngine;
using System.Collections;
public class AnimateTest : MonoBehaviour {
[Range(0.0f, 1.0f)]
public float slider;
private Animation animationComponent;
private AnimationClip animationClip;
void Start () {
animationComponent = GetComponent<Animation>();
animationComponent.enabled = true;
animationClip = animationComponent.clip;
animationComponent[animationClip.name].weight = 1;
animationComponent.Play();
animationComponent[animationClip.name].speed = 0;
}
void Update () {
animationComponent[animationClip.name].normalizedTime = slider;
}
}
Your answer
Follow this Question
Related Questions
Instantiate a prefab and then add a animator component and controller to the component. 2 Answers
parameter does not exist in concroller 1 Answer
Animator does not contain definition for "runtimeAnimationController" 0 Answers
Animator not playing animation on function call from other script 0 Answers
Mecanim "trigger" parameter behaviour with multiple animator layers 1 Answer