Search Unity

Question Beginner question on relative sizes of text elements on a canvas

Discussion in 'UGUI & TextMesh Pro' started by Mpx83, Apr 11, 2023.

  1. Mpx83

    Mpx83

    Joined:
    Apr 4, 2023
    Posts:
    21
    Hi,
    I'm sure that this is really simple but I cannot find a solution and I am a complete beginner.

    In the scene editor I created a very simple 2d scene with a canvas and inside it some text boxes.
    The textboxes are TextMeshPro objects.
    I would like to set one textbox to be 20% of the width of the canvas and 50% of the height of it, and to keep these proportions if I change the dimensions of the canvas.

    To do this, in the Anchors presets I select the "stretch" option and put the anchors to the corners of the parent canvas. Then I set the X scale to 0.2 and the Y scale to 0.5. This method seems to work but the problem is that also the text is scaled both in the X and Y directions and it looks weird.

    Is anyway to avoid the scaling of the text or is any other method to achieve what I need?

    Thanks for your help
     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    602
    For the most part never touch the scale of canvas objects.

    If I understood what you want correctly you should set the anchors to 0.2 and 0.5 accordingly. In the simplest cases for place it in bottom left corner set anchorsMin to (0, 0) and anchorsMax to (0.2, 0.5). If you want top right corner use (0.8, 0.5) and (1, 1). After changing anchors set left, right, bottom, top to 0.
     
    Mpx83 likes this.
  3. Mpx83

    Mpx83

    Joined:
    Apr 4, 2023
    Posts:
    21
    Worked like a charm! Thanks!