- Home /
Question by
Sirmaiji · Feb 25, 2013 at 12:46 PM ·
buttonif-statementsifkeypress
Blocking one button's function when other pressed
I wonder how to make let's say "Fire3" button which is for running not being interrupted by another button's function "Fire1" - which is for aiming (which means a run cycle shouldn't be interrupted by aiming action)? What do I need to write in "if" line code for button "Fire3"? Thanks in advance for assistance :) Here's a piece of my code:
if (Input.GetButton ("Fire3")){
walkSpeed = 5.15;}
if
(Input.GetButton ("Fire3") && Input.GetAxis ("Vertical"))
animation.CrossFade ("run");
if (Input.GetButton ("Fire1")){
animation.CrossFade ("aiming");
walkSpeed = 0;
run = 0;
}
Comment
Best Answer
Answer by AlucardJay · Feb 25, 2013 at 01:28 PM
It is all about how you organize your logic. Try reading the instructions as a computer would.
If there is Fire3 then do this_1, or else do this_2.
// check for Fire3
if ( Input.GetButton ("Fire3") )
{
walkSpeed = 5.15;
// check for movement
if ( Input.GetAxis("Vertical") )
{
animation.CrossFade("run");
}
}
// no Fire3, check for other inputs
else if ( Input.GetButton("Fire1") )
{
animation.CrossFade("aiming");
walkSpeed = 0;
run = 0;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613093352im_/https://answers.unity.com/themes/thub/images/avi.jpg)