- Home /
A button press is not working unless I also press an axis at the same time.
My void Update() is calling Movement(), and the following code is within it. _all_Taps is displayed on screen, so I can easily verify if Special_1 is pressed.
bool _is_Special_Pressed = Input.GetButton("Special_1");
switch(_is_Special_Pressed)
{
case true:
_all_Taps = "SP BUTTON";
break;
case false:
break;
}
In my input manager I erased all default Inputs and created three; x-axis, Y-axis, and Special_1.
Special_1 has a positive button named "joystick button 5" Gravity is set to 0 Dead is 0.001 Sensitivity is 1000. Type: Key or Mouse Button. Axis is X Axis Joy Num is Get Motion from all Joysticks.
I think it's all correct. However, when I press Special_1 nothing happens unless I ALSO press either axis. I fairly new to Unity and have no clue as to how I can fix it.
Any help would greatly be appreciated.
Thanks!
I also just realized that I'm receiving an Argument Exception: Input Button Submit not setup.
I tried Googling a solution with no luck. Still searching.
Thanks.
UPDATE: I reset my input settings and restored the Submit, Cancel, etc., so the error went away. I then re-created my Special_1. Still not working. In the drop_down for Axis, I must select X, Y, or a numbered axis, but it's not an axis.
Answer by xibanya · Dec 24, 2019 at 02:19 AM
Is there anything you need to have happen if the button is not pressed? As-is, _all_Taps will be set to "SP BUTTON" when the button press is detected but nothing will ever unset it.
Also, GetButton returns true when the button is held down, not for when it's tapped. For that, use GetButtonDown. Additionally, if you are using C#, there is no need to use a switch statement for a bool, you can just use if.
try replacing that entire snippet with
if (Input.GetButtonDown("Special_1")) _all_Taps = "SP BUTTON";
else _all_Taps = "negative condition label";
Also, in case you'd like to rename your input buttons later, it's a good idea to keep the name in one place that you can access everywhere else in your code. so I recommend somewhere in your code (maybe in a class that deals the most with input) put this:
public const string SPECIAL_1 = "Special_1";
A constant can be accessed any time without needing to initialize the class. You don't have to give your constants names in all caps but it's a common convention to do that in C# so that when you see the variable name you know immediately that it's a constant.
Once that's set up, you can poll for that input like this: if (Input.GetButtonDown(SPECIAL_1)) doThing();
and if you change the name of that button later, you just need to update the constant and don't need to hunt through all your code for all the places you've written it. Additionally, if you want to find every place you check input for this button press, you can right click the variable name and select Find All References.
You can click the items in the list that shows up to jump to that place in code.
Your answer
![](https://koobas.hobune.stream/wayback/20220612220532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use Canvas Buttons as Input Axis 1 Answer
Mouse Button vs Get Button 1 Answer
D-Pad as Button instead of Axis 3 Answers
How to replace input axis keyboard button with touch button? 3 Answers