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
0
Question by Shiro_Rin · Oct 18, 2015 at 12:20 AM · animation2dinputanimatorgetbutton

GetButton will only play animation when held down

How do I play an animation completely with Input.GetButton ? It'll only play the complete animation if the button is held down.

 if (Input.GetButton ("Attack1")&& grounded==true && IsMoving==false) {
             Anim.Play("Attack1");
             IsAttacking=true;
         }

That is the snippet of code I am using for attacking. So far it works, but only if I hold down the button. I want it to play completely tho. Any help ?

Comment
Add comment · Show 6
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 PictonicStudio · Oct 18, 2015 at 03:26 AM 0
Share

Why not use $$anonymous$$ecanim? It's much simpler

avatar image Shiro_Rin · Oct 18, 2015 at 03:29 AM -1
Share

I am using mecanim. It's 2D sprite. Anim is a reference to an Animator component. I fixed it my own way. I use coroutine's to detect if an attack is going and it plays the animation.

avatar image PictonicStudio Shiro_Rin · Oct 18, 2015 at 04:02 AM 0
Share

But, you should use Anim.SetBool/Float/Int

avatar image TrickyHandz · Oct 18, 2015 at 04:33 AM 0
Share

I see you fixed this your own way, but for reference you should look at how you are handling input:

 // This will play the animation while the button is being held down 
 if (Input.GetButton ("Attack1")&& grounded==true && Is$$anonymous$$oving==false) {
              Anim.Play("Attack1");
              IsAttacking=true;
          }
 
 // This will play the animation when the button is pressed
  if (Input.GetButtonDown ("Attack1")&& grounded==true && Is$$anonymous$$oving==false) {
              Anim.Play("Attack1");
              IsAttacking=true;
          }
 
 // This will play the animtion when the button is released
  if (Input.GetButtonUp ("Attack1")&& grounded==true && Is$$anonymous$$oving==false) {
              Anim.Play("Attack1");
              IsAttacking=true;
          }

avatar image Shiro_Rin TrickyHandz · Oct 18, 2015 at 04:36 AM 0
Share

I tried GetButtonUp , and it did the same thing.

avatar image TrickyHandz Shiro_Rin · Oct 18, 2015 at 04:42 AM 0
Share

In that case, the problem may exist in the $$anonymous$$ecanim state machine. If a state has no exit time (i.e. looping animations) and the state can be interrupted, it will leave in the middle of the animation depending on the conditions. This is one of the reasons that most people use parameters to drive the states and transitions rather than calling Animator.Play() to jump directly to a state.

2 Replies

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

Answer by Shiro_Rin · Oct 18, 2015 at 03:30 AM

I fixed it using coroutine's. My own way I guess

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
avatar image
0

Answer by DireDoesGames · Oct 18, 2015 at 09:13 AM

You might be able to put the Anim.Play("Attack1"); in the IsAttacking variable.


If my answer helps you please accept it and up vote it! Thanks!

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

47 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

change order in layer via animation window? 1 Answer

2d Top Down Enemy Control (LoZ type) 0 Answers

How to have an animation loop only twice 1 Answer

2D Animator: how to get rid the animation "blending" 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