Allow Click Through some UI Elements

Hello, I am using IsPointerOverGameObject() method to prevent clicks through UI elements. It’s working perfectly but I want to click through some UI elements with different tags. How can I do it? Thank you.

If you want some UI elements to basically be “invisible” to clicks, there are a few options

  1. set “raycast target” to false on individual elements (images, text)

  2. make the elements you don’t want to recognize clicks children of a CanvasGroup with “interactable” and “blocksRaycasts” set to false

  3. to actually use tags as you mention, you’ll want to have a special script attached to the canvas that holds these objects. Make sure that canvas has a GraphicsRaycaster component and then in Start use GetComponent to assign that to a variable like graphicsRaycaster. Also have a private PointerEventData pointerEventData; Then for your IsPointerOverGameObject, have something like

        bool IsPointerOverGameObject()
            pointerEventData.position = Input.mousePosition;
            graphicsRaycaster.Raycast(pointerEventData, out List<RaycastResult> results);
            foreach (RaycastResult result in results)
                if (result.gameObject.tag != "ignore")
                    //whatever other evaluation logic
                    return true;
            return false;