Starting an animation on a certain frame
Hello, I've spent many hours reading the Animation manual and browsing Unity answers and I think I have taken the wrong approach for my implementation. Could you please orientate somebody new in Mecanim? Thanks in advance.
I have a Clock clip, running from 12am to 12pm. I want to be able to initialize the animation so it starts at the time of the day I want. For this purpose, I have implemented a ClockRunningBehaviour class and I want to change the time OnStateEnter().
I have found a function, AnimationState.time, which should provide the functionality I need. However, I don't know how to get my AnimationState object OnStateEnter():
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Animation animation = animator.GetComponent<Animation>();
foreach (AnimationState state in animation)
{
// This is never hit, there are not AnimationStates!
//state.time = desiredTime;
}
}
Is my approach correct? How would you implement a Clock (provided the animation clip)? Thanks!
Answer by irreverent · Feb 23, 2017 at 04:51 AM
My question was replied in https://www.reddit.com/r/Unity2D/comments/5vh3s0/starting_an_animation_on_a_certain_frame/
Thanks for following
Answer by TractGames · Feb 27, 2019 at 09:31 PM
Making it easier for future users:
Animator.Play("animationName", layer, time);
// to play from frame x without having to worry about layers
Animator.Play("name", 0, x);
Your answer
Follow this Question
Related Questions
Can't play an animation from the Animator 1 Answer
Animation Constantly Playing? 1 Answer
Character rolls forward,but slides back after animation 2 Answers
Why isn't my animation looping? 3 Answers