- Home /
how to display a single frame of a sprite animation
I've created an animation using 2d sprites. First, I imported my sprite sheets into my project. Then, I used the sprite editor to splice it up into a grid of frames. Finally, I drug it into the scene and Unity created the game object, an animation, and a controller.
Now, I would like to display a selected frame of the animation on a texture. The reason I want to do it this way is so that I can time the animation with an audio source. I'm using the audioSource.time value to drive the animation. Here is a snippet from my code.
//get the percent done of the audio
fltPercentDone = audioSource.time / audioSource.clip.length;
//figure out which video frame to show to stay in sync with audio
intFrame = (int)(intTotalFrames * fltPercentDone);
//set the frame on the sprite
DisplaySpriteFrame(intFrame);
I just need to know the property on sprite, controller, or animation to display a selected frame.
Thanks in advance,
Mike
Answer by awest · Jul 17, 2014 at 12:47 AM
Does the character operate in this way throughout the game? If that is the case, I would ditch the animation and store the frames as a texture array. Then switch the texture to the next one in the array whenever you want.
If not you may want to use one of the method from this question - jump to a specific frame in an animation.
I'm actually doing this as a work-around for 3D movie textures in mobile applications. The $$anonymous$$oveTexture class doesn't work in Android or iOS projects. So, I'm trying this out as a work-around