Offset between mouse cursor position and "hit" position with worldspace UI's
Hello,
I am noticing a problem with my worldspace gui's.
It seems that my UI elements (I have tested this with buttons and text input field) do not have the correct collision bounds in world space. The actual hitbox of the graphic raycast is offset from the button or ui element.
This image should show what I am talking about:
The red debug line shows the direction of the users view (and location of the mouse pointer on the screen). The yellow button with "ECM" written on it is being triggered (yellow is its active state) but the red line is not actually in contact with the button.
This problem occurs with all of my gui's, in both the editor and the build.
I can't seem to track down a solution to this. I replaced the built-in graphicraycast script with one that I found on github, but the issue was the same.
With larger gui buttons, the offset is less noticeable, but I need to make some fairly complex gui's with lots of buttons, which means I need to solve this issue. Does anyone have any ideas?
I am using Unity 5.6.
Answer by Sinhtulenh · Nov 02, 2017 at 05:36 AM
I have a problem similar to yours. If you find a solution, please tell me...
Yes, as a matter of fact I did discover a solution to this. I don't have the code in front of me right now, but I believe what I did was I added a simple offset to raycast being used to select buttons, etc. It seems that this solution, even thought it's a little crude, works at all resolutions and in all circumstances that I tested it.