Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 JackoMiG · Jul 09, 2015 at 08:23 AM · animatormecanimweaponboolgetbutton

Animator parameter stays true after mouse button released.

Hi guys,

I'm currently scripting my weapon to work with the animator component. The weapon fires ray cast and does everything it needs to just fine. The problem seems to lie within the animator.

It is supposed to play the 'fire' animation (on a loop) when "Fire1" is held down and go back to 'idle' or 'walk' when "Fire1" is released.The parameter for this is a bool. So as you can guess when "Fire1" is held down the bool goes to 'true'. However, after releasing "Fire1" the bool does not return to 'false' and simply stays 'true'.

Fire1 released after being pressed alt text

I've included all the snippets of code that I think are relevant to the function of this.

 //variables
     var fireRate : float = 0.5;
     private var nextFire : float = 0.0;
     
     //--//
     
     if(player_AllowFire) //player is allowed to fire?
         {
             if(Input.GetButton("Fire") && !Input.GetButton("Sights") && Time.time > nextFire) //did the player just hit the "fire" button?
             {
                 PullTrigger(); //pull the trigger - (not firing yet)
             }
         }
     //code continues
     //==//
     
     function PullTrigger() //trigger pulled- now it's either "click!" or "bang"
     {
         if(currentWeapon.clipAmmo != 0 && Input.GetButton("Fire") && !Input.GetButton("Sights") && Time.time > nextFire) //are there still bullets in the clip? 
         {
             nextFire =  Time.time + fireRate;
             currentWeapon.gameObject.GetComponent(AudioSource).PlayOneShot(currentWeapon.sfx_WeaponFire); //play weapon fire audio, just once
             
             animator.SetBool("Fire",true);
 
     //code continues for a bit (still the same function below)
 
     else //uho, no bullets in the clip- click click PANIC!
         {
             animator.SetBool("Fire",false);
     }


Can anyone figure out what is happening here?

dump17.jpg (58.1 kB)
Comment
Add comment · Show 2
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 Torigas · Jul 09, 2015 at 08:26 AM 0
Share

if that is the whole code, there are some brackets missing. in the pulltrigger function before the else a closed bracket and after the closed bracket from the else part a closed bracket to close the pulltrigger function.

avatar image JackoMiG · Jul 09, 2015 at 08:52 AM 0
Share

I've included all the snippets of code that I think are relevant to the function of this.

It is closed in the full script.

1 Reply

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

Answer by JackoMiG · Jul 09, 2015 at 09:36 AM

My god I'm an idiot. I forgot to add in an else statement in the section before the PullTrigger function. There was no condition for the parameter to be false except for when the player runs out of ammo! Fixed now:

 if(player_AllowFire) //player is allowed to fire?
     {
         if(Input.GetButton("Fire") && !Input.GetButton("Sights") && Time.time > nextFire)
         {
             PullTrigger(); //pull the trigger - (not firing yet)
         }
         else
         {
             animator.SetBool("Fire",false);
         }

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

22 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

Related Questions

Mecanim attack State won't stop Looping or exit 1 Answer

Mecanim and Lightwave 11 1 Answer

Mecanim: Backward animations only work in preview, not in game 3 Answers

Head Look for Mecanim 1 Answer

Why does this animator appear to occupy two states, but report only one? 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