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
1
Question by Jammer3000 · Dec 14, 2012 at 05:23 PM · animationfps

How to run an animation clip on button down-hold?

Hi I am working on a fps shooter game, and im new to coding so I have no idea how to do this. What I need to do is run an animation on button down click and if the person holds the "w" key down the animation will continually until he lets go(button up). Its for the leg animation in my fps game, I want it so when the player holds down the "w" key he can look down and see the legs running while he's running. Thanks

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

1 Reply

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

Answer by clunk47 · Dec 15, 2012 at 03:36 AM

I'm assuming you have your animations / frames setup already. Here is a SIMPLE EXAMPLE in C# to get you started.

 if(Input.GetKey(KeyCode.W))
     animation.Play();
 else if(Input.GetKeyUp(KeyCode.W))
     animation.Stop();

You will need to have basic coding skills to use this correctly. If in C# you need to have it inside a class... For more information look at the Unity Script Reference for Animations

Comment
Add comment · Show 2 · 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 Jammer3000 · Dec 16, 2012 at 01:21 AM 1
Share

Thank you thats exactly what I needed, is there anyway you could add four variables to that, because I want when the player clicks W S D A they will all play there animation which is the leg moving animation, A will be the left walking animation D will be the right W will be forward and S will be the backward walking which they will all have there own, I would, but like I sed before im not very good so I don't know how, plus the little bit I know is java, Thanks.

avatar image clunk47 · Dec 16, 2012 at 01:28 AM 2
Share
 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.W))
     animation.Play("forwardWalk");
 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.S))
     animation.Play("backPedal");
 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.A))
     animation.Play("leftStrafe");
 if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.D))
     animation.Play("rightStrafe");
 else if(!Input.any$$anonymous$$ey))
     animation.Play("idle");

If you don't have an "idle" animation, just use animation.Stop(); If you want a smooth transition, you would use animation.CrossFade("animationName", fade time). But this will get you started at the very least. Also take a look at the Unity Script Reference for Animation

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

10 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

Related Questions

How to click a 3d object in unity3d? 3 Answers

Scores/points when you destroy something? 1 Answer

problem with weapon animation -.- 0 Answers

Problem with First Person Shooter Script 1 Answer

Weapon Possition Move On Sprint 1 Answer


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