- Home /
How to choose a keyFrame from script
i'm new to animation in unity, but I can't seem to find the answer anywhere. So I have an animation, that begins with a tiny cube and gets bigger from the first keyFrame to the 60th keyFrame. The idea is that I want to choose how far along the animation to be depending on the distance of between the cube and the player, which is no issue (I know which keyFrame I need to be on), except that I don't know how to choose that keyFrame. Is it even possible in Unity?
Comment
Answer by Basher207 · Mar 17, 2015 at 10:02 PM
I found the answer elsewhere, I can reference an animation using:
void Update() {
keyFrameIWant = 1; //0 being the first frame in the animation, 1 being the last (because of normalised Time)
MyAnime ["AnimationName"].normalizedTime = keyFrameIWant
//AnimationName has to be on the Animation component of the gameObject that the script is on
//(MyAnime is just a reference from the start Function
}
sorry for bad english.