- Home /
Reverse Animtion On clicking text.
hello, This code Reverse animation for only once , if we click another time it does not working.
Script 1 for animation when click on 3Dtext[box collider]
var playing : boolean = false;
var gameobject : GameObject;
function OnMouseDown ()
{
if (!playing) {
playing = true;
gameobject.animation["Credit"].speed = 1.0;
yield WaitForSeconds(gameobject.animation["Credit"].length);
playing = false;
}
}
script 2 for reversing animation on clicking 3Dtext [Boxcollider]
var playing : boolean = false;
var gameobject : GameObject;
function OnMouseDown ()
{
if (!playing) {
playing = true;
gameobject.animation["Credit"].speed = -1.0;
yield WaitForSeconds(gameobject.animation["Credit"].length);
playing = false;
}
}
This thing is working good but here's my problem if user click again on the script1 text animation i mean after clicking on Script2 which reverse animation when it comes back to original state clicking on script1 text doesn't work ....
thank you
This is a exact same problem im having at the moment 4 years after heh, Im using 2 scripts eaxctly like you one for normal animation and then a " back " button for reverse animation. but the button only works once
Answer by Santa · Jul 09, 2012 at 12:40 PM
As far as I understand you need to rewind it first to the end.
playing = true;
gameobject.animation["Credit"].time = gameobject.animation["Credit"].length; //
gameobject.animation["Credit"].speed = -1.;
yield WaitForSeconds(gameobject.animation["Credit"].length);
Thanks for your answer :D but what i need Is how to do animation anytime when i click...i mean like when user like on text animation play's then if he click back button animation reverse ...this thing is working good but here's my problem if user click again on the text animation does not working...it working for only once.....Actually am using another script to do forward animation.....
Do you have any idea or any other script which does the same thing......
sorry for being unspecific.
So you just need to switch looped animation? If user press Forward it goes forward. And if Back then backward. Right?
I updated my question ...hope it gives you a clear idea :D
If Animation.wrap$$anonymous$$ode is Once then it will stop react after one play. You need to do Animation.Play(...) after each speed change. And probably insert:
gameobject.animation["Credit"].time = gameobject.animation["Credit"].length;
or
gameobject.animation["Credit"].time = 0;
as I answered.
Answer by Ingen · Jul 09, 2012 at 04:15 PM
Hi, if you don't absolutely need/want an animtion can try this for a gui
look at the second, the AdvancedMarquee.cs
with a bit more code I think can add button to switch direction of scroll
unifycommunity- AdvancedMarquee.cs
Your answer
![](https://koobas.hobune.stream/wayback/20220613073919im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Upon stopping my animated object, it doesn't return to it's initial position? 3 Answers
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Can I make animations snap to a frame? 1 Answer
Animation.CrossFade waiting for transition to finish 1 Answer