Hey I wanna make a mobile game where on the start menu touching anywhere will start the game, but i also want a few buttons to press on the same screen, how do I make it so if you touch a button it doesn’t recognize the normal click as well
I am just going with my workaround as I couldn’t get anything “legit” to work how I wanted it to
//blank style so screen button doesnt show up
var blankStyle : GUIStyle;
var buttonPressed = false;
function OnGUI () {
if (GUI.Button(Rect(0,0, 500, 500),"Test Button"))
{
buttonPressed = true;
}
//button is screen size and has a blank gui style
//this \/ must be at the bottom so the other buttons can disable its use
if (GUI.Button(Rect(0,0, Screen.width, Screen.height), "", blankStyle))
{
if(!buttonPressed)
{
//do stuff for touching screen
}else
{
buttonPressed = false;
}
}
}
The simplest way I can think of is to put all the button code in if / else if block.
if (Input.touchCount > 0) //firstly, check if a touch has been made
{
if (GUI.Button(...)) //code for options button
{
// statement
}
else if (GUI.Button(...)) //code for stats button
{
// statement
}
else if (GUI.Button(...)) //code for quit button
{
// statement
}
else //this block will execute if none of the above is true
{
//statement for starting the game
}
}
Didn’t check the code, but should be something similar. Hope this helps.
Hello everyone.I tried above code but can’t.I’m making a 2d platform game.My character will jump when touch on screen.My problem is when i click on pause game button on screen then Touch still always active.And that make my character automatic jump when click on Pause button.How to my chacracter can’t jump when i click on pause button.Please help me.Thanks a lot.