- Home /
One button press is triggering two functions unintentionally?
I have a menu where a button called "Submit" can be triggered when a player presses the X button on a PS4 controller (Input.GetButtonDown). This brings up another menu that also has a button that is triggered with the X button. When I press down the X button on the first menu, I guess Unity reads this continuously and not discretely, and so the press of the X activates both buttons. How would I get it so that the user has to press the button twice and the menus work as intended?
Answer by medinaline · Jan 10, 2020 at 12:14 AM
You might also consider using Input.GetButtonUp() instead. That will fire when you let go of the button rather than when it is recognized as being pushed down.
I have had luck with that to avoid getting repeating hits.
Answer by SecretAgentMango · Jan 09, 2020 at 10:21 PM
So I came up with something, it works but it's pretty hacky. I create an int called "xButtonPressed" that starts at a value of 2. After I press X, both buttons get triggered, but instead of jumping to the code that does what the 2nd button is supposed to do, I instead subtract one from "xButtonPressed"; I have an if-statement that only jumps to the code once xButtonPressed == 0.
Your answer
![](https://koobas.hobune.stream/wayback/20220612221318im_/https://answers.unity.com/themes/thub/images/avi.jpg)