Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Arvank · Dec 13, 2012 at 11:56 AM · animationpauseplayanimationstateshowcase

Creating a play/pause button for animations.

Hey guys, might be a bit of an odd request here. I'm working on creating an application that is going to serve as a showcase for 3D animations. The user can turn the camera around the character and the showcase contains basic functions that most media players have as well.

One of the first and most important of these functions is a button that can pause the current animation when pressed, and resume it when pressed again. At the moment I'm having a bit of trouble with this one. I can't seem to get the player to resume the animation after having paused it. A crucial element of the program is that the user can slow down or speed up the animation by pressing corresponding buttons. This means that when the user pauses the player at 0.5 animation speed, it should resume at that same speed. Right now I'm doing this by saving the animation speed to a float variable, tmpSpeed, on the moment the user presses the pause button. Then when the player presses the button again to resume the animation, it calls the saved animation speed again and resumes.

Below is the code that I have so far:

 function PausePlayAnimation(anim: Animation){
     var isPlaying: boolean = true;
     var tmpSpeed: float;
     
     for(var state: AnimationState in anim){
     
     // Pause the animation
         if(isPlaying == true){
             tmpSpeed = state.speed;
             state.speed = 4;
             isPlaying = false;
             Debug.Log("Pausing animation, state.speed is: " + state.speed + ". tmpSpeed is " + tmpSpeed);
         }
     
     //Play the animation
         else if(isPlaying == false){
             state.speed = tmpSpeed;
             isPlaying = true;
             Debug.Log("Resuming animation, state.speed is: " + state.speed + ". tmpSpeed is " + tmpSpeed);
         }
     }
 }

Right now the function is being called when the space bar is pressed. But as soon as I press it, it seems to run through the loop three times before finishing. On top of that, the animation only pauses when the space bar is pressed TWICE. When reading the Console for my debug logs it says:

First Press

Pausing animation, state.speed is: 4. tmpSpeed is 1
Resuming animation, state.speed is: 1. tmpSpeed is 1
Pausing animation, state.speed is: 4. tmpSpeed is 1


Second press

Pausing animation, state.speed is: 4. tmpSpeed is 4
Resuming animation, state.speed is: 4. tmpSpeed is 4
Pausing animation, state.speed is: 4. tmpSpeed is 4


I was wondering if this was a problem because of the fact that I'm using a for loop to check the animation states? I don't really know any other method to check and/or change the animation speed, so I decided on using this.

If you guys need any more information, let me know. I hope you guys can help me out with this, because I have no clue.

Cheers!

Comment
Add comment · 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 Arvank · Dec 17, 2012 at 10:09 AM 0
Share

Hey guys, small update for anyone trying to help me out here..

I discovered the pretty obvious fact that the the function being ran three times is, of course, because of the fact that the for-loop is dependent of the amount of animations I had on my gameObject. At the time, I had three animations in the list, and the for-loop just executed the function for each animation in there.

Now I know the specific problem, I'm stuck on finding a solution. I don't know of any different way to call the animationState of my current animation, without using the for-loop that I'm using now. Does anyone know of any alternate ways of calling my animationState?

Cheers!

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

I am attempting to play an animation in reverse and slow it down, But it only seems to play forwards. 2 Answers

Animation ["1"].speed = 0; Doesn't work 2 Answers

How do I combine a GUI scroll with an animation? 1 Answer

Set up Animator with specific seconds 1 Answer

'speed' is not a member of 'Object'. when pausing 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