Touch GUI

Hi,

I am wondering if there is a way to tell if a touch does NOT hit a GUI button/joystick. I have tried the inverse, by writing

if (GUI.Button...etc)
     // run GUI code
else
    // run game code

This, quite obviously, will check to see if you are on a GUI button, and if you are not, it’ll run my other code.

The reason I am doing this is because I am creating a 3rd person video game, in which the player selects his target by tapping the enemy. The player deselects by tapping a space on the screen in which nothing is present. (If you’ve ever played WoW, think of how you select and deselect characters.) However, whenever I press the attack button, my target is deselected.

Essentially I am looking for something along the lines of

if (touch !OnAnyGUIElement) 
    // run game code
else
   // run GUI code

Any insight?

you will have to create a function that knows all rects to check against.

But actually your approach won’t go anywhere anyway, for granted.

UnityGUI (OnGUI) is for menues, but useless for ingame menues
as such I would recommend that you look into another solution like spriteui, guimanager etc

I see, thank you very much! I’ll take a look at to those tomorrow.

Just so I know how much time I’ll have to allocate for the new UI in the morning, how steep is the learning curve for these add-ons? Is there good documentation? Would you recommend one over the other?

Thanks!

They are commonly pretty simple once you understood the basics (its not like buttons are that hard and buttons and 2-3 other things are basically all you will have unless you buy EZ GUI or use GUIX for which you though need to do the editing / building on the desktop editor).
The freely available ones commonly don’t come with docs