GetButton Problem

Here’s a part of code:

if (Input.GetButton ("Aiming")){
    target.animation.CrossFade ("aiming");
    walkSpeed = 0;}


if (Input.GetButton("Aiming")){
      
if (Input.GetButton("Action")){
     
      target.animation.CrossFade("shoot",0.1);
}}

What I actually tend to achieve is make it work like so: if Aiming button pressed then aiming animation’s played and only after that I can press button Action to perform shooting action(play shooting animation). But on the other hand if Action button pressed first and then I press Aiming button, I don’t want shooting action happen and let character stay in idle pose just like no button was pressed. I guess I need somehow block Aiming Button Input when Action button is pressed. Any ideas how to achieve this? Thanks for your feedback :slight_smile:

Try using a boolean.

bool canShoot;

if(Input.GetButton("Aiming"))
    canShoot = true;

else
    canShoot = false;

if(canShoot)
{
    if(Input.GetButton("Action"))
    {
        target.animation.CrossFade("shoot", 0.1f);
    }
}

If you are using JS, bool canShoot would be

var canShoot : boolean;