- Home /
Tap anywhere and buttons (android)
I am making a game and i want that in the main menu whenever the player touchs the screen the game would start.(the pass to start the game works) the only problem is that i have another buttons in the screen(like mute button or button to get into the store) and when i click them nothing happens because its passing the player to the game.
if (GUI.Button(Rect(0 ,0 ,100 ,100),"" , muteButton)){//Mute button
//Code to mute
}
if(Input.GetMouseButtonUp(0)){//TapAnywhere
//Start the game
}
I tried it with else if and its still doesn't work.(And all the code is in GUI Function)
Do you simply want touch? Input.anykey for editor and Input.touchCount works if that is what you want.
You dont understand me, the tap anywhere already works, but if i have a button in the screen then its blocking it.
Answer by smallbit · Jun 17, 2015 at 05:03 AM
You either make sure that the mouse click position (REF happens in the area without button (i.e. bottom 80% of the screen) or even simpler create a very big invisible button which will start the game. For that you will need to drop using old GUI.button and use some more evolved solution like Unity UI (version 4.6 upwards) or NGUI. In that way you can adjust collider to not overlap with other buttons. If you really need the area to touch to start the game to be anywhere even between your other buttons, than set this button depth to lower (so its below the other buttons), that would work with NGUI not sure about unity canvas. If you however want to stick to use basic GUI.buttons track mouse click position and only start the game when is not overlapping the screen. In practice this area dont need to cover entire screen just big chunk of the middle.
Is Input.mousePosition gives me the exact x and y just like where i place it in the Rect( , , ,)?
You need to test it out ? use debug.log(Input.mousePosition) in Update to see what it gives you. I think it goes from 0,0 (left bottom corner) to screen.width,screen.height top right corner. so in your case if you want the bottom 70% of the screen you would do something like :
if(Input.Get$$anonymous$$ouseButtonUp(0) && Input.mousePosition.y < Screen.height*0.7f)
{//Tap on the bottom 70% of the screen
//Start the game
}
but than again just test it out
Actually i already fixed it, thank you for your help. What i did is: I checked if theres a button click and if the click is not in the button bounds(for example the mute button Rect is (0,0,100,100) so: if(Input.Get$$anonymous$$ouseButtonUp(0) && Input.mousePosition.x > 100 && Input.mousePosition.y > 100){ //Start game
You should definitely check your solution on different resolutions, since you use absolute values it will work, thus on big screens (i.e. retina) your buttons will be very small. Thus you should adapt button size and the mouse click code in relation to screen width and heigth
Your answer

Follow this Question
Related Questions
display txt file content on textarea GUI Android 1 Answer
Android touch gui help!!! 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Android Options Menu 0 Answers
Saving items to a text file 1 Answer