-1
\$\begingroup\$

Code:

var click=false;
var anmtr:Animator;

function Update () {

if(Input.GetButtonDown("Fire1")){

    click=!click;
    anmtr.SetBool("clk",click);
}

if(Input.GetButtonUp("Fire1")){

     click=!click;
}

}

The value of click variable in inspector is changing as I click and release the mouse button.But the value of the Animation parameter is changed from false to true on first button down event and then it stays true forever even after releasing the mouse. No matter how many times I click the mouse button it stays true. But not the variable click it changes as expected.

\$\endgroup\$
1
  • \$\begingroup\$ sorry found the error \$\endgroup\$ – coder_86 Jun 28 '17 at 12:27
0
\$\begingroup\$

The reason is, when you release the button, you don't update the anmtr; Since you are just toggling the bool in both if's, you could simply do this:

if(Input.GetButtonDown("Fire1") || Input.GetButtonUp("Fire1") ){
    click=!click;
    anmtr.SetBool("clk",click);
}

Why? Easier to read.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.