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 infamouslyuseless · Dec 19, 2013 at 05:25 PM · animationjavascriptpunch

Punch Animation Doesn't Work And Others Do...

This is my script, javascript (I'm using mecanim):

 if (Input.GetButton("Fire1"))
         {
             punch = true;
             if (punch == true)
             {
                 animator.SetBool("Punch", true);
             }
             
                 
         }
 
         if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
         {
             sprint = true;
             if (sprint == true)
             {
                 animator.SetBool("Sprint", true);
             }
         }
         
         if (Input.GetKey(KeyCode.W))
         {
             run = true;
             if (run == true)
             {
                 animator.SetBool("Run", true);
             }
         }
         
         else
         {
             animator.SetBool("Run", false);
             animator.SetBool("Sprint", false);
             animator.SetBool("Punch", false);
         }

There's nothing wrong with the variables, as they're all fine. For some reason all the animations work except for the punch animation. The punch animation only works when I'm running... it's not to do with "Fire1" either, I've checked and fire1 is the left mouse button. I've tried doing Input.GetMouseButtonDown(0) and the same thing happened as with fire1. Please can someone find a solution to this please!

when I click left click, punch does become true, but doesn't play the animation.

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 Sundar · Dec 19, 2013 at 05:51 PM 0
Share

comment this line like //animator.SetBool("Punch", false); and test

avatar image infamouslyuseless · Dec 19, 2013 at 05:55 PM 0
Share

It works, but it keeps on repeating...

avatar image Sundar · Dec 19, 2013 at 06:01 PM 0
Share

You have to follow your game play logic (when) to stop punching. $$anonymous$$y suggestion would be use an IEnumerator function to stop punching after x secs(say)

avatar image infamouslyuseless · Dec 19, 2013 at 06:07 PM 0
Share

could I just make a function that when punch is true doesn yield WaitForSeconds(amount of seconds that the animation is), then make punch false, would that work? and what's IEnumerator?

avatar image Sundar · Dec 19, 2013 at 06:11 PM 0
Share

Check this http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.StartCoroutine.html

Show more comments

1 Reply

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

Answer by Sundar · Dec 19, 2013 at 06:57 PM

Its not complicated, try this

 if (Input.GetButton("Fire1"))
 {
    punch = true;
    if (punch)
   {
       animator.SetBool("Punch", true);
       StartCoroutine(StopPunch(2.0)); 
   }
  
  
 }
 
 function StopPunch (waitTime : float) {
         
         yield WaitForSeconds (waitTime);
         animator.SetBool("Punch", false);
     }
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 infamouslyuseless · Dec 19, 2013 at 07:23 PM 0
Share

Thanks a lot for your help, this was an annoying thing in my game and now it works! I appreciate the help :D

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

19 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

Related Questions

Animation play when dead 2 Answers

Java Script: Clock script help. 1 Answer

Animation Script not working. 1 Answer

Animation Script Error 1 Answer

Script block animations and other scripts 2 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