I have searched around for an answer to this with no avail… I have seen some suggestions of using raycasts etc but seems like overkill.
Basically I want to test if a touch position is over a GUI button.
I am currently doing it by saying if the touch position x and y are less than button position ± button size x and y etc
This does (sort of) work apart from when changing resolutions (or indeed on different devices).
The problem is the size of the button, the position seems correct from the rect component and that even changes correctly for a given resolution.
I thought I was onto a winner when I thought of using the standard dimensions and scaling the buttons size from the canvas scaler controlled canvas when checking x and y are within that limit but it isn’t working properly…
Well, I use the touch so that I can press anywhere on the screen to pick a target position. The problem I am having is that if I press a UI button (say a pause button) the touch is used as well as the button being pressed, so I get a target pos being set and then the pause kick in.
omg, thanks so much, i have been looking for this solution for way toooo long.
For the people who dont want to do any work themselves:
ButtonContainsPosition(touch.position)
var m_xButtonRect = button.GetComponent();
And Public Canvas m_xMenuManager;