Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by jimmyismike · Jun 21, 2011 at 12:20 AM · animationtriggerlooptriggerslooping

Looping animation while key down

Heres animation trigger script

 function Update () {
   if(Input.GetKeyDown("f")) {
     animation.Play("Gun and run");
   }
 }

I want to set it so if i hold down f the animation loops and when i let go of f the animation stops

Comment
Add comment · Show 8
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 save · Jun 21, 2011 at 12:27 AM 0
Share

How about adding an else to that if. ;-)

 else if(animation.isPlaying("Gun and run")){
     animation.Stop("Gun and run");
 }

Also have a look at additive animations and animations in layers (where you'd be able to combine two animations of gunning and running at the same time).

avatar image jimmyismike · Jun 21, 2011 at 12:41 AM 0
Share

No your not gunning and running i was just bored and named it that its just one simple animation of your arms moving.

avatar image jimmyismike · Jun 21, 2011 at 12:43 AM 0
Share

Didn't seem to work

avatar image save · Jun 21, 2011 at 12:47 AM 0
Share

I stand corrected. Although, giving things semantic names will help you better here in the future (perhaps not in this case).

avatar image save · Jun 21, 2011 at 12:53 AM 0
Share

Accidently had a capitalized I on is, try either without the complete "else if"-statement and just go with "else" or switching I to i on isPlaying. Always look in the console for hints of errorneous script.

Show more comments

1 Reply

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

Answer by Joshua · Jun 21, 2011 at 03:01 AM

 function Update () {
 if(Input.GetKeyDown("f")) {
     animation.Play("Gun and run");
 }
 if(Input.GetKeyUp("f")) {
     animation.Stop("Gun and run");
 }
 }

note that the answer provided in the comments is incorrect since GetKeyDown will only return true for the frame the key is pressed, not for the frames afterwards when it's kept down. It would work if he'd had used GetKey

Comment
Add comment · Show 1 · 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 save · Jun 21, 2011 at 09:49 AM 0
Share

Cheers, seems like I ran out of brain juice. :-)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Mecanim triggering an animation from object 2 Answers

Light animation and Main Menu animation at same time from 1 trigger 0 Answers

How To Wrap A Blender Animation??? 1 Answer

I can't put animations on loop. 1 Answer

Mecanim animation Looping problem (Unity 4.6) 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