• 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
0
Question by Craxter · Apr 05, 2011 at 09:56 PM · animationpingpong

How to use PingPong animation without repeatation??

i want to open and close a door with same button... i use PingPong but when i press key to open it.. its starts repeating the animation... and if i use once it do it just one time and after pressing againg it again open the door

i just want to use same open animation in reverse...with same key what do to. ??

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Apr 05, 2011 at 09:58 PM

Do This: http://answers.unity3d.com/questions/45189/reversing-door-animation

var open : boolean = false;
Update() {
 if (Input.GetKeyUp("k")) {
   open = !open;
   if (open)
     .. play forward .. 
   else
     .. play backward ..
  }
} 
Comment
Add comment · Show 7 · 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 Craxter · Apr 05, 2011 at 10:03 PM 0
Share

but how to do this with the same key to open it and close it?

avatar image DaveA · Apr 05, 2011 at 10:37 PM 0
Share

Look for Input.Get$$anonymous$$eyUp("k") and have a boolean called 'open' that is toggled, somethng like the above

avatar image DaveA · Apr 05, 2011 at 10:37 PM 0
Share

You could of course also look for Get$$anonymous$$eyDown ;)

avatar image Craxter · Apr 05, 2011 at 11:31 PM 0
Share

ok ..but still animation is not working in reverse...

avatar image Ben Holmes · Apr 05, 2011 at 11:40 PM 0
Share

use a negative speed to play the animation backwards, you shouldn't use pingpong for this.

animationState.speed = -1.0f; //<- like this

Show more comments
avatar image
0

Answer by KevinCodes4Food · Apr 23, 2014 at 08:41 PM

For those searching for a solution to use PingPong only once, without repeating, I have seperate solution post here:

Ping Pong Only Once

In terms of playing an animation just forward, then just backwards on a key stroke, which seems to be the actual intent of the query in this posting, here is a complete C# implementation derived from DaveA's clever answer above.

 bool isOpen = false;
 
 void Update() {
 
     if (Input.GetKeyDown(KeyCode.K))
     {
         isOpen = !isOpen;
         if (isOpen )
         {
             animation["open"].time = 0;
             animation["open"].speed = 1;
         }
         else
         {   
             animation["open"].time = animation["open"].length; // Start at the end...
             animation["open"].speed = -1; // ...and run backwards!
         }
         
         animation.Play("open");
     } 
 }
 


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

1 Person is following this question.

avatar image

Related Questions

Can I make animations snap to a frame? 1 Answer

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

can't find pingpong mode in Unity 4.6? 0 Answers

Play animation forward than immediately backwards, once (ie single pingpong) 2 Answers

pingpong animation question 2 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