Search Unity

[v2017.1.0f3]Canvas : Rect Transform Resize - Render Mode [Solved]

Discussion in '2D' started by viktouille, Jul 24, 2017.

  1. viktouille

    viktouille

    Joined:
    Jul 19, 2017
    Posts:
    9
    Hello,

    Sorry if it's a noob question, but when I try to resize my grille_canvas to fit in canvas, it didn't worked.

    I work with Unity v2017.1.0f3 in 2D.

    I tried to change with this script:
    Code (CSharp):
    1. rectTransform.sizeDelta = new Vector2( yourWidth, yourHeight);
    that i found here [http://answers.unity3d.com/questions/775779/change-size-of-the-new-ui-rect-transform-using-scr.html]
    and here [http://answers.unity3d.com/questions/973572/recttransform-wont-resize.html]
    but it didn't found sizeDelta.

    I also know this [https://stackoverflow.com/questions...-canvas-or-change-any-of-the-transform-values] so I tried other Render Mode like World Space but when I try any combination of Width/Height, it zoom anormally and in the same way.

    Width:2048 - Height:1531


    Width:6000 - Height:3000


    So do you guys have a solution to resize my Grille_canvas?

    Thanks in advance! :D
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    If you set up a child of a Canvas to have anchors set to stretch with no offsets, the child will automatically resize to fit the Canvas.

    Capture.PNG

    Child RectTransforms are positioned and sized using anchors which are positioned relative to the parent.
     
  3. viktouille

    viktouille

    Joined:
    Jul 19, 2017
    Posts:
    9
    Thanks for your answer but my Canvas (named Grille_Canvas) can't be a child of something :/

    btw: I found the answer of my problem, I didn't know there were a setting were your can add your own resolution here

    Seems that I can manually change the width and the height manually of the display in the render mode Screen Space - Overlay
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Your Canvas is the parent, your Image should be a child object. My screenshot would be the settings of the child, which stretches to fit the size of the Canvas.

    Those settings in the Game tab will let you preview what your UI will look like using different resolutions, so your Canvas will resize accordingly. That is not the resolution that your game will use in a build, necessarily. The game will still try to fit whatever aspect ratio it's displayed on, with the Canvas resizing according to how you set it and its children up.