Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

UI Text Position to GameObject position (Pixels to Units)

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by Grafer, Nov 1, 2015.

  1. Grafer


    May 30, 2015
    Hello there.

    I am trying to make score boards. The problem is I have no idea how to make UI Text stay at the same position as a score board. Here's example of what I mean. At the certain resolution the result is excatly what I want, but you need to change the resolution only by a little bit to mess everything up.

    The GameObject stays at the position of (1.8, 4.1, 0) and that's perfectly fine. It adjusts to screen width and height. But the text position is rigidly assigned to some place in a game space using pixels (126.1, 122.1, 0). What's the best way to make them stay at the same position together no matter what resolution is chosen.

    I'd be very grateful for your help or hints.
  2. Senshi


    Oct 3, 2010
    I suggest looking into the new anchor system; it's really powerful!

    In this case, you'll want to set the anchors to match the four corners of the background (or perhaps a little smaller), with an offset of 0 on all sides (left, right, top, bottom). This will ensure the text won't move when the resolution changes.

    Next, you'll probably want to enable "Best Fit" on your Text Component. This resizes the text to always fit within its bounds, no matter the resolution.
    Grafer likes this.