- Home /
The question is answered, right answer was accepted
Buttons on disabled canvas still catching keypresses
I have a weird bug in my code where pressing space seems to be triggering a button on a canvas that's recently been disabled.
So at the end of my game I show a canvas with 2 buttons, "back to menu" or "continue playing".
"Keep playing" calls a function which disables the canvas. I use this code below:
goalCompleteCanvas.GetComponent(Canvas).enabled = false;
But then if I press space, it calls the function of the button that was clicked again, even though the canvas was disabled and the buttons are hidden. If I press a cursor key and use space I can actually select the other button too.
How can I hide this canvas and stop any of the buttons from being triggered?
goalCompleteCanvas.gameObject.SetActive(false);
should do the thing?
If you don't want to disable the whole GameObject you can attach a Canvas Group Component and then set the alpha to zero and uncheck Interactable and blocks Raycast, the con of this is that it is still rendered even though the alpha is set to zero.
Answer by daviddickball · Jul 02, 2015 at 09:35 PM
Oh wait, I could just disable the gameObject instead of the component.
No idea why I didn't think of that.
I'm an idiot.
Follow this Question
Related Questions
Canvas button with 2 functions onClick must be pressed twice for 2nd function? Will not disappear? 1 Answer
Parent with animator component prevents child buttons to get click 0 Answers
Animator Not Playing on Button Click 0 Answers
Whole Screen Touchable 0 Answers
UI button does not press if colliding with other UI object 1 Answer