Search Unity

Question Positioning a UI Element so the top right corner of its child lines up with the screen edge

Discussion in 'UGUI & TextMesh Pro' started by MELTPACK, Dec 13, 2022.

  1. MELTPACK

    MELTPACK

    Joined:
    Apr 7, 2017
    Posts:
    151
    I'm making a ammo counter that goes along the side of the screen, and to make it take as minimal room as possible on the screen, i'd like to push it as far over to the right side as i can. upload_2022-12-13_15-22-23.png

    My plan is to make the top right corner of the top bullet line up with the edge of the screen, making all bullets visible while taking up as little room as possible
    upload_2022-12-13_15-23-17.png
    My problem is, Unity simply does not want to do this. I'm not even sure how to. I've taken the max of the top bullet's rect, then the anchoredPosition of the pink background, and then subtracted the anchorpos's world position from the top right position of the bullet (again, in world coordinates). when adding this offset to the background, it simply doesn't show up properly, only showing about half of the bullet. What's wrong? How could I do this?
     

    Attached Files: