Play animation backwards from GUI after it has been played forward.

Hi Guys,

I want to have a single GUI button to play an animation forward and then when it is pressed again to play the animation backwards, I have done it before but I cant remember how :frowning:

So far I can play the animation on a GUI button now I want to be able to press it again and for it to play it backwards. Do I need to use a boolean?

var skin : GUISkin;
var btnImage : Texture;


function OnGUI () {

if(GUI.Button(Rect(Screen.width / 2 - 100, Screen.height - 160, 300,150), btnImage, "label"))
{
animation.Play();
}

}

Thanks
Dan

You will need to access the animation frames in a loop and run through them from last to first. Anyhow, there are lots of responses to this question already. Just Google “unity play animation backward” or something like that.

Here’s one example:

http://forum.unity3d.com/threads/15071-playing-animation-backwards