- Home /
Pressing 2 Buttons at the Same Time
I'm making a shooter that fires a special bullet when two buttons are pressed at once. Is the code for this as I think it is?
if (Input.GetButtonDown("Fire1" && "Fire2"))
Answer by AlucardJay · Dec 16, 2012 at 06:34 PM
close ....
if ( Input.GetButtonDown("Fire1") && Input.GetButtonDown("Fire2") )
each time you are checking for a condition, you have to check them seperately, you cannot combine them like you were =]
Just a note : this is hoping that you press both the keys in exactly the same frame, I don't know what the odds are of that happening. You may need timers for both, then check if they are just GetButton but not timed out (say 0.2 seconds).
Hi, I'm having a similar issue, trying to add direction based attacks to a platformer. Using your setup as an example; if (Input.GetButtonDown(KeyCode.DownArrow) && Input.GetButtonDown(KeyCode.Z)) { Attack_Jump_Down(); }
But I get an error "Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'UnityEngine.KeyCode' to 'string' Assembly-CSharp
Any ideas? I have had no luck finding info elsewhere.
GetButtonDown takes a string as input, as defined in the input settings. You should either add your keys to that list, or you can use Input.GetKeyDown instead. See my answer below if you want to solve the ti$$anonymous$$g issue in this answer though.
Answer by bobbaluba · Nov 30, 2020 at 03:41 PM
I would do
if ((Input.GetButton("Fire1") && Input.GetButtonDown("Fire2"))
|| (Input.GetButtonDown("Fire1") && Input.GetButton("Fire2)))
The first line checks if you press 2 while holding down 1, the other checks if you press 1 while holding down 2.
This way, you don't have to press both on exactly the same frame.
Your answer
Follow this Question
Related Questions
Rapid fire script? 4 Answers
Hold Button Shooting 3 Answers
input fire error? 3 Answers
Get enemy to fire at me from a high position 0 Answers
Fire bullet into the direction my player is facing 2D 2 Answers