- Home /
Button to play animation in reverse
Hi Guys, I could use some help with getting a second button to play the animation in reverse.
My first button plays the animation of a box opening and I want the second button to close it. Ive been looking around the forum and web but cant find any solution.
Here is my code so far. The open button plays the animation forwards (how I want that one to) but the close button does the same, it resets the object to the start of the animation and plays it forward the same as the first button. Any help would be great. Thanks
function OnGUI () {
if(GUI.Button(Rect((Screen.width * 0.5) - 100, Screen.height - 110, 300, 75), openbtnImage, "label"))
{
animation.Play("Take 001");
animation["Take 001"].speed = 1;
}
if(GUI.Button(Rect((Screen.width * 0.5) + 10, Screen.height - 110, 300, 75), closebtnImage, "label"))
{
animation["Take 001"].speed = -1;
animation["Take 001"].time = animation["Take 001"].length;
animation.Play("Take 001");
}
}
Answer by sethuraj · Oct 30, 2013 at 03:34 PM
Your button positions are overlapping.Here is the screen shot.
Use a less value for button width.Instead of 300 use a value like 100 or less
void OnGUI ()
{
if(GUI.Button(Rect((Screen.width * 0.5) - 100, Screen.height - 110, 100, 75), "Forward"))
{
animation.Play("Run");
animation["Run"].speed = 1;
}
if(GUI.Button(Rect((Screen.width * 0.5) + 10, Screen.height - 110, 100, 75), "Back"))
{
animation["Run"].speed = -1;
animation["Run"].time = animation["Run"].length;
animation.Play("Run");
}
}
Cheers... :-)
Your answer
Follow this Question
Related Questions
Play multiple reversed animations with animation.PlayQueued 0 Answers
Why is Animation Not Playing in Reverse? 2 Answers
Animations aren't playing in reverse. 0 Answers
Playing animation backwards 1 Answer
Animation reverse 1 Answer