Search code examples
unity-game-enginehierarchy

Some Objects in Prefab instance not response the click event


I have multi-numbers browser windows in the Unity app, the newly opened window will popup to the front. enter image description here

I want to call the clicked window to the front, so I attached a Hierarchy script.

public class Hierarchy : MonoBehaviour, IPointerDownHandler
{
    [SerializeField] private RectTransform topWindow;
    // Set clicked object to top
    void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
    {
        // Print debug message to the console
        Debug.Log("Object clicked: " + eventData.pointerCurrentRaycast.gameObject.name);

        topWindow.SetAsLastSibling();
    }

}

But windows only response to the front when it's title bar be clicked, click else where doesn't work. I checked it only detect click event when the title bar be clicked, but not detected click event when click browser area. enter image description here

Here is the hierarchy in the Prefab, BrowserWindow is the entire are of the window. BrowserBackground is the dark background wraps browser. Browser2D is the Prefab for rendering browser. ControlButtons is the title bar include the page name, close button and detail button.

enter image description here

Anyone can figure out what is this problem comes from?


Solution

  • Try turning off the Raycast Target of an Image that is not related to a click event.

    • Unity Event takes into account the before/after relationship of objects.
    • Unity Event responds to Image and Collider.
    • Unity Event does not respond when Raycast Target is turned off.

    enter image description here

    If it does not work, it may work better if you use a click-only transparent Image for the foremost side. BTW: Transparent images are heavy. You can solve this problem by turning off "Cull Transparent Mesh".

    enter image description here