- Home /
Alternative to EventSystem.current.currentSelectedGameObject
currentSelectedGameObject only works when navigation is enabled. However, I need to have navigation off.
Are there any other ways to achieve the same effect?
I would rather have a central script managing all of this instead of code snippets scattered everywhere checking whether that GameObject is being selected or not (i.e. not the interfaces in EventSystems).
Answer by MasterChameleonGames · Jun 06, 2019 at 01:23 PM
Using GraphicRaycaster.Raycast worked.
PointerEventData pointer = new PointerEventData(EventSystem.current);
pointer.position = Input.mousePosition;
List<RaycastResult> raycastResults = new List<RaycastResult>();
graphicRaycaster.Raycast(pointer, raycastResults);
if(raycastResults.Count == 0) return false;
GameObject selectedUIElement = raycastResults[0].gameObject;
Your answer
Follow this Question
Related Questions
When i press play the buttons work, however, the buttons dont work on my iphone. 1 Answer
EventSystem events reaching parent EventTrigger? 0 Answers
Changing the target of a button that takes a gameobject as a parameter? 0 Answers
Is reference better than UnityEvent ? 1 Answer
Is there a way to fire the inspector events from code? 0 Answers