My game has something happen whenever you click the screen. I don’t want that to apply if you’re just pressing the buttons. Is there any way to check if you’re just clicking anywhere else?
If it is a mobile app (touchscreen only), and assuming that hitting ANYWHERE on screen regardless of if a button is hit or not, you want something to happen, you could simply do this:
if (Input.touchCount > 0)
DoSomething ();
But if you want it only to happen when your not pressing a button on the UI it gets more complicated, as you have to check for GUI hits first, then if it was not on a button or whatever, only then do you have it do the… other thing?
I won’t write the (working) code to do that for you - but here is sort of how I think about it:
bool buttonTapped = false;
void Update()
{
if (Input.touchCount > 0) // check for any touch at all anywhere
{
if (!buttonTapped)
DoSomething ();
}
}
void ButtonTapped() // in the inspector we setup this method to be called when a buttons hit
{
DoStuffThisButtonDoes ();
buttonTapped = true;
}
Of course after your button is tapped, and it does whatever it does, you would need to set buttonTapped back to false to allow the… other thing to happen ![]()