- Home /
The question is answered, right answer was accepted
Button is being triggered by spacebar after clicked once
I have a pause button in my space shooter game. When I pause, then un-pause, every time I use the space bar to shoot, it triggers the pause button. Is this because the pause button stays focused after being pressed once? Is it possible to un focus the button? I am using unity's 4.6 GUI system.
Pause button code:
`public void pause(){
if (Time.timeScale == 1) {
Time.timeScale = 0;
pauseText.enabled = true;
mainMenuBT.gameObject.SetActive(true);
} else {
Time.timeScale = 1;
pauseText.enabled = false;
mainMenuBT.gameObject.SetActive(false);
}
}`
Any help in the right direction would be very much appreciated.
Answer by Kyle_WG · Jun 09, 2015 at 04:21 PM
Sorry if irrelevant to you now but I thought I'd add for anyone else that comes across like me.
You can set the Navigation part of the UI.Button to None so it doesn't keep focus. It acts like a form so you can easily navigate from one UI element to another (like when you tab to other fields etc.) Mine was defaulted to automatic.
Unity version 5.0.0b18.
I had the same problem and your solution was perfect. Cheers $$anonymous$$yle!
Thanks! In my scenario, after clicking a button once the next click anywhere would trigger it again. Changing Navigation to None has fixed that and made it only fire when clicked!
Great! Really surprised that it uses Automatic by default. Glad it helped.
Thanks $$anonymous$$yle, that was simple and helpful.
Answer by kevinspawner · Dec 22, 2014 at 10:39 AM
You need to create a bool and to trigger the pause on and off when required. Currently you are just scaling the time scale 1 and 0. You need to create a private or public bool and then enable and disable it to trigger the pause function. Hope it helps.
Thanks for the reply. I actually just got it to work. Turns out that space bar was an alternate positive in the Input $$anonymous$$anager for the button. I had to go to Edit > Project Settings > Input. Then under Submit, I reassigned the Alt Positive Button to something other than the space bar. I can now Pause then un-pause and shoot with the space bar without accidentally triggering the pause button every time.
Follow this Question
Related Questions
Can't get 4.6 GUI Button to Load Scene (Solved) 1 Answer
Launching an animation with new GUI in Unity 4.6 1 Answer
(4.6 UI) Button is highlighted permanently 3 Answers
How do I reset GUI Button to normal state texture(Android)? 0 Answers
How to create a button for every supported resolution? 1 Answer