animation.Rewind Issues

Hi all,

Been working on a script that I just can’t seem to get right. What I’d like is for the user to click one button, and have an animation play. This works fine, but by pressing the second button the user rewinds the animation and this is the script that I haven’t been able to get work. Any suggestions? Below is the code. I’ve tried using animation.Rewind and animation.Speed – set to -1.

private var animationName = “01stage1”;
var thingIWantToAnimate;

function Awake()
{
thingIWantToAnimate = GameObject.Find(“_01Scene”);//Maya file which has the animation
}

function OnMouseDown ()
{

thingIWantToAnimate.animation.Play(“01stage1”);
thingIWantToAnimate.animation[“01stage1”].speed = -1.0;
//thingIWantToAnimate.animation.Rewind(“01stage1”);

}

(please note - animation.Rewind is commented out, as it didn’t work.)

hmm, i´m really not sure, but have you tried to call the speed = -1.0 line before the Play execution?

note that Rewind class does not play the animation backward, just set the anim player to the first frame…

Tried that, but no luck. Any other thoughts? Or does anyone have some code that works that I could play around with?

does the animation was made in Unity or 3d Modeler externally ?..

if you have made in Unity, then try to duplicate the animation file (in project panel) with a different name (for instance : rewindAnim.anim), attach this second animation to the object you want to rewind. Go to the animation window, and change the key frames!, put the last keyframe to the start, and the first keyframe to be the last, with this, you will simply invert the animation., remember to set clamp the animation mode for both animations…

Then in your script just comment or delete the line where you put the “speed = -1” or “animation.Rewind” and write this :

thingIWantToAnimate.animation.CrossFade("rewindAnim");

Note that, if you have made your animation in Maya, is the same process, but you must to invert the frame inside Maya…