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 MrRocotos · Oct 10, 2013 at 06:42 PM · animationspeedkeygetkey

Controlling animation speed

Greetings! I've got such a question:

I want to control my animation movement speed by pressing a key on a keyboard. For example, when the specified key is held, animation plays (play speed 1.0), but when I release the key it should stop (play speed 0.0). And when I will press the key again it continues from the point where it was stopped.

I'm trying to deal with it in this way:

 function Update (){
       if(Input.GetKey("page up"))
       animation.Play("animation_name");
       animation["animation_name"].speed= 1.0;      
       else
       animation["animation_name"].speed = 0.0;
       }


It doesn't work, saying: BCE0044: expecting }, found 'else and something like that. I know that I do it wrong, but don't know how will be correct. I wish if only you could help me with this task. Just some advices. PS: I have read practically every topic concerning this question, but still don't understand.

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
3
Best Answer

Answer by clunk47 · Oct 10, 2013 at 07:21 PM

The error is because you have more than one command in your if statement, but didn't open / close the if statement with brackets. Go from there. Also check to see if your animation is already playing or not before you play it, so it doesn't start over each time.

 #pragma strict
 
 function Update ()
 {
     if(Input.GetKey("page up"))
     {
         if(!animation.isPlaying)
             animation.Play("animation_name");
         
         //This isn't part of your if(!animation.isPlaying) condition.
         animation["animation_name"].speed= 1.0;
     }
     
     else
         animation["animation_name"].speed = 0.0;
 }
Comment
Add comment · Show 3 · 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 clunk47 · Oct 10, 2013 at 08:05 PM 1
Share

Please refrain from stacking questions, ask you new question as that, a new question so that others have a chance to help, and others will be able to more easily find information on this new issue on UA.

avatar image clunk47 · Oct 10, 2013 at 08:06 PM 1
Share

If this resolved your first issue, as a user you are required to Accept the answer (check mark). And, not required, but you can also upvote answers or comments that are helpful to you (thumbs up).

avatar image MarkD · Oct 10, 2013 at 08:07 PM 1
Share

Normally the negative form should reverse the animation speed and thus the animation itself.

And if it really does not work, simply make a revers going animation and insert it in a separate slot.

avatar image
0

Answer by austintone · Jan 07, 2017 at 08:21 PM

you're missing the bracket before and after the 'if' statement begins and ends. You have to end the 'if' statement before you start the 'else' statement. It should be this:

 function Update (){
        if(Input.GetKey("page up")) {
        animation.Play("animation_name");
        animation["animation_name"].speed= 1.0; 
        }     
        else {
        animation["animation_name"].speed = 0.0;
      }
  }
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.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Can I make animations snap to a frame? 1 Answer

How can I get animation state speed in code 1 Answer

How to select keys in the animation editor? 1 Answer

Speed button for animations? 2 Answers

Not Run while Aiming; Slope Terrain Making Object Faster 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