• 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
6
Question by Reaper1121 · May 12, 2015 at 08:28 AM · c#animationreverse

Unity 5. Reverse animation play ?

Hello. How do i play animation in reverse? i been searc$$anonymous$$ng in internet and i found t$$anonymous$$s:

 animation["Zoom"].speed = -1;

but its outdated now or i am doing t$$anonymous$$s wrong. How do i play animation in reverse using unity 5? i start animation like t$$anonymous$$s:

 bonuspanel.GetComponent<Animation> ().Play ();

soo it should be the same just like t$$anonymous$$s:

 bonuspanel.GetComponent<Animation> ().speed = -1;

But speed does not exist. I hope someone can help me :)

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
12
Best Answer

Answer by HarshadK · May 12, 2015 at 08:38 AM

The solution by careyagimon is in t$$anonymous$$s forum thread playing animation backwards.

It states:

I t$$anonymous$$nk you need to set when the animation is playing from first. Playing it backwards from 0.0 doesn't do anyt$$anonymous$$ng. You need to play it backwards from the end of the animation.

Code (csharp):

 hand.animation["bridge"].speed = -1;
 hand.animation["bridge"].time = hand.animation["bridge"].length;
 hand.animation.Play("bridge");

Even better is if you can set the wrap mode to ClampForever. Play the animation once at speed 1 and then set the speed to -1 to reverse back to the starting state.

Comment
Add comment · 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 Reaper1121 · May 12, 2015 at 08:45 AM 0
Share
avatar image HarshadK · May 12, 2015 at 08:58 AM 0
Share
avatar image Reaper1121 · May 12, 2015 at 09:13 AM 0
Share
avatar image kalibcrone Reaper1121 · Jun 01, 2017 at 01:14 PM 0
Share
avatar image HarshadK · May 12, 2015 at 09:14 AM 0
Share
avatar image
13

Answer by brainpower · Feb 21, 2016 at 04:27 PM

Despite what Jasper_Moore said about speed multipliers, they worked for me.

Here's what I did:

1) Add a float parameter to the Animator (I called it "Direction"). Initialize its value to 1.0.

2) In the relevant animator state (in my case "Walking"), link the float parameter to the speed multiplier, like so: alt text

3) In your script, set the float parameter to -1.0 (for backwards) or 1.0 (for forwards), like t$$anonymous$$s:

animator.SetFloat("Direction", -1.0f);


speedmultiplier.png (10.6 kB)
Comment
Add comment · 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 hoarfrost31 · Oct 21, 2017 at 06:29 PM 0
Share
avatar image methodin · Mar 31, 2018 at 07:01 AM 0
Share
avatar image DiegoMontania · Jun 07, 2018 at 02:34 AM 0
Share
avatar image NicolasCEMU · Nov 09, 2018 at 10:44 AM 0
Share
avatar image henimex · May 30, 2020 at 10:10 AM 0
Share
avatar image
1

Answer by Jasper_Moore · Aug 20, 2015 at 11:16 AM

W$$anonymous$$le it would make sense to simply change the playback speed, or to create a float value in the animator for a speed multiplier, I have found it to be very inconsistent and buggy, if it works at all. The only consistent method I've found is stepping through the animation manually, like so:

public Animator myAnim; //Animation controller, assign in inspector.

private float animTime; //Tells us where we are in the animation's timeline.

private bool anim_Play; //Should the animation play?

void Update() {

     if (anim_Play && animTime < 1)           //If animation is toggled on
         animTime += 0.3f * Time.deltaTime;   //Increase animTime, Don't let animTime go beyond 1
     else if (!anim_Play && animTime > 0)     //If animation is toggled off/reversed
         animTime -= 0.3f * Time.deltaTime;   //Decrease animTime, Don't let animTime go below 0

     myAnim.Play("Some_Animation", 0, animTime ); //Step through animation manually

}

//Call t$$anonymous$$s function to toggle forward/reverse. public void ToggleAnim() {

     anim_Play = !anim_Play;

}

T$$anonymous$$s is a simple setup for a single animation (in my case, a door opening/closing). The animation will automatically idle at beginning and end. If you want it to do somet$$anonymous$$ng else after playing, you'll have to experiment to work that out. Also, I used 0.3 for the speed multiplier, t$$anonymous$$s can be adjusted to fit your needs. Hope t$$anonymous$$s helps anyone having t$$anonymous$$s problem!

Just to be clear, Here is what my animator view looks like for t$$anonymous$$s setup: alt text


capture.png (42.0 kB)
Comment
Add comment · 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
0

Answer by yankun1997 · May 05, 2017 at 09:34 AM

T$$anonymous$$s is how i do,mine is quite straightforward

 private animatior anim;

 private float direction;

void update () {

      if (Input.GetKeyDown("space"))
     {
         anim.SetFloat("Direction", -1);
         anim.Play("WAIT02", -1, 0f);
     }

}

and you must set a float parameter in the animator (a transition) , in my case it's named direction.

hope it works for you

Comment
Add comment · 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

27 People are following this question.

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

Related Questions

Hey,Im making a game, and I need to reverse my 3D animation, how do I do that? 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Animation at the end of the level 1 Answer

"Lerp" back to original position after animation. 0 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