Detect all the differents UI elements under mouse

Hello everyones !
I am currently developing a RTS like project where I have to be able to select objects by two ways :

  • Click on it to select a single object.
  • Drag to select multiple objects.
    Both methods are implemented so far, but I would like to be able to get the list of all the UI elements under my mouse when I click. So I could know if the user actually mean to click on UI or a gameObject.

I can’t just check if the user clicked on GUI or not because when the user drag to select multiple object I draw a square from the moment he clicked, so the user always click on GUI…

So far I tried using GraphicRaycaster.Raycast like :

        PointerEventData    ped = new PointerEventData (null);

        ped.position = Input.mousePosition;
        List<RaycastResult> results = new List<RaycastResult> ();

        gr.Raycast (ped, results);

But results.Count was always equals to 0.

Thanks for your help ! :smile:

Okay … I found the solution here :

Sorry for the double post.

2 Likes