Search Unity

Check if UI images in world space overlap with each other

Discussion in '2D' started by tataragne, Sep 11, 2019.

  1. tataragne

    tataragne

    Joined:
    Aug 15, 2009
    Posts:
    27
    Hello there,

    I have placed 4 UI buttons in my scene with a Canvas set in World space. Right now, I'm trying to get the distance of each other from the camera, change their hierarchy accordingly to prevent clipping, then check if two UI rects overlap each other and make the overlapped one dissapear (by changing its alpha).

    So far, I've managed to get the clipping and the fading right, but I still can't detect if two buttons overlap each other correctly. Since it is in 3D space, I have to take into account the rotation of the UIs, and since I've added a lookAt() script to my buttons, they always face the camera. I've found a function called Rect.Overlaps() to detect that, but it only works in 2D.

    Think of my problem as a movable UI on top of players during a match session. I want the UI to always be facing the camera whil also sorting them according to their distance to the player, and make dissapear those in the back row which are being overlapped by those on the front.

    Any idea on how to get the overlapping right ? I struggle desperately to solve it, it's all I need to have my system complete. Thanks for your answer.