Hi, I’m working on a first person game where users often interact with World Space UI panels using their view/look.
I want to somehow set up the UI so that it highlights and presses when the screens center point is over the UI elements instead of when the mouse cursor is over the UI elements.
Before anyone suggests it, I am already using a locked cursor, which achieves the desired effect when the game is run in a window, but when the game is run in fullscreen the locked cursor state doesn’t work the same way
You can do a raycast into the world from the screen center and have it collide only with the UI layer and make decisions depending on the result of the raycast. Here is a piece of code that I used to discard swipes that begin over a UI element. You can do something similar. Hope this helps.
private bool shouldDiscardSwipe(Vector2 touchPos) {
PointerEventData touch = new PointerEventData(EventSystem.current);
touch.position = touchPos;
List<RaycastResult> hits = new List<RaycastResult>();
EventSystem.current.RaycastAll(touch, hits);
return (hits.Count > 0); // discard swipe if an UI element is beneath
}