Search Unity

How to know if mouse is over a canvas group children ?

Discussion in 'UGUI & TextMesh Pro' started by Rafarel, Jul 8, 2019.

  1. Rafarel

    Rafarel

    Joined:
    Jul 21, 2017
    Posts:
    199
    Hi, I have several canvas group for my UI system and I want to know if the mouse is over one of my canvas groups and know which one it is ?

    I tried this but I have only the list of UI elements, not the their group, any way to know if they are attached to a group ?

    Code (CSharp):
    1. PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
    2. pointerEventData.position = Input.mousePosition;
    3.  
    4. List<RaycastResult> raycastList = new List<RaycastResult>();
    5. EventSystem.current.RaycastAll(pointerEventData, raycastList);
    6.  
    7. for (int i = 0; i < raycastList.Count; i++)
    8. {
    9.     Debug.Log(raycastList[i].gameObject.name + " " + i);
    10. }
    Thanks !
     
  2. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,048
    Did you ever find the answer?