- Home /
Hold down 2 buttons and do something
I wonder how to make if I hold down W and Shift it will do something. I think I should do It like this but I'm not sure
if(Input.GetKey("W" && "LeftShift");
function blahblah()
"noob" is not an appropriate tag. How about ins$$anonymous$$d of checking whether two buttons are pressed down, check whether one button is pressed down and another button is also pressed down.
Answer by zharik86 · Jun 08, 2014 at 09:28 AM
I think, change your code to
if(Input.GetKey("W") && Input.GetKey("LeftShift")) {
//this is your function blahblah
}
$$anonymous$$eep in $$anonymous$$d that this way the function blahblah will be called as long as you're holding down 'W' and 'LeftShift'. If for instance you hold those two buttons down for 1 second you would've called the function blahblah as many times as the FPS is. If you change it to Input.Get$$anonymous$$eyDown you'll have to lift the key to execute the function blahblah again. :-)
@Burla Yes, certainly you are right. But I wrote it as an example for understanding. If to be exact, it is possible to enter bool variable:
private bool go = false;
void LateUpdate() {
if(Input.Get$$anonymous$$ey("W") && Input.Get$$anonymous$$ey("LeftShift")) {
if (!go) {
go = true;
//your function
}
}
if(Input.Get$$anonymous$$eyUp("W")) {
go = false;
}
}
Or use Get$$anonymous$$eyDown, how you say.
I had no offensive intentions when I made this comment, don't doubt me. I just thought that this was a useful input to have in $$anonymous$$d. :-)
@Burla Simply, that you wrote is suitable for the majority of cases. But, for example, won't be suitable for relocation of the character when he changes from a step to run. In this case it is necessary to check key press always:)
this looks great. I will try both scripts to see what I like more!
Your answer
Follow this Question
Related Questions
Animation Not playing? (Noob) 1 Answer
If I let shift go restore fov 1 Answer
Changing Rate of Change from Key Key Input Values 1 Answer
access Input.GetButton key name 1 Answer
[ASNWERED] How To Change Button To An Alphabet Key 2 Answers