- Home /
Help check click out of UI
I'm developing an mobile game and I'm working on the initial menu. There are 4 buttons on the menu. If the player presses a button, a certain menu is opened, and if he presses anywhere else on the screen (so not on a button) the game is started. What control can I use to make sure that if I click a button, the game does not start too?
Are you saying the game currently does start when you click a button and its not supposed to? The button should stop clicks from going through and activating another collider. I am probably missing something though.
Answer by James2Games · Dec 05, 2018 at 10:14 PM
A simple approach would be to add a button behind the menu covering the entire screen. Give it an image component and set the alpha to 0 so it's not visible. Since it's behind the menu then the menu will be clicked first before the button that was just added.
When that button is pressed tell it to start the game.
oooh. I really like that! where in the editor can you set a button in front of behind the others.
Thank you for your answer, but I had already thought and tested this solution, but the result did not satisfy me because to start the game, using this method, you need two clicks (one to remove the panel and one to start the game). I would rather that the game started immediately at the first click if no button is pressed.
@surfuay Unless you have multiple Canvas's or CanvasGroups then the order in the Hierarchy window deter$$anonymous$$es what in the UI is in front of what. The lower it is then the further infront of the UI the object will be
@Vallo92 You can check for a click ins$$anonymous$$d of using a button. If the user clicks outside the window then close the popup. https://answers.unity.com/questions/947856/how-to-detect-click-outside-ui-panel.html
Answer by surfuay · Dec 05, 2018 at 08:15 PM
I think it might be easier to create a start button as well so maybe a fifth button. and that button would set the other buttons to inactive.