• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Dee Va · Jul 09, 2012 at 11:53 AM · animationonmousedown

Reverse Animtion On clicking text.

hello, T$$anonymous$$s 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;
 
    }
 
 }
 

T$$anonymous$$s t$$anonymous$$ng is working good but here's my problem if user click again on the script1 text animation i mean after clicking on Script2 w$$anonymous$$ch reverse animation when it comes back to original state clicking on script1 text doesn't work ....

thank you

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image felixfors · Feb 11, 2013 at 05:34 AM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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);
Comment
Dee Va

People who like this

1 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dee Va · Jul 09, 2012 at 01:08 PM 0
Share

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.

avatar image Santa · Jul 09, 2012 at 01:14 PM 0
Share

So you just need to switch looped animation? If user press Forward it goes forward. And if Back then backward. Right?

avatar image Dee Va · Jul 09, 2012 at 01:34 PM 0
Share

I updated my question ...hope it gives you a clear idea :D

avatar image Santa · Jul 09, 2012 at 01:39 PM 1
Share

If Animation.wrapMode 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.

avatar image Santa · Jul 09, 2012 at 02:35 PM 0
Share

Which of them? :)

avatar image

Answer by Ingen · Jul 09, 2012 at 04:15 PM

Hi, if you don't absolutely need/want an animtion can try t$$anonymous$$s for a gui

look at the second, the AdvancedMarquee.cs

with a bit more code I t$$anonymous$$nk can add button to switch direction of scroll

unifycommunity- AdvancedMarquee.cs

Comment
Dee Va

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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? 0 Answers

How to select an animation clip by index number? 7 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges