Search Unity

Anchoring elements relative to a fixed aspect ratio parent

Discussion in 'UGUI & TextMesh Pro' started by FlyingSquirrels, Apr 15, 2016.

  1. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    84
    Hey all,

    I am trying to anchor a close button on an image. Sound easy right? The 'CatImage' is set to preserve aspect and with anchors at (0.1, 0.1) to (0.9, 0.9). The close button (as seen in image 2 below) is set to anchor to the Top Right Corner. This works fine in some resolutions as you can see below.

    Image 1:

    Image 2:
    When I change the aspect ration to 16:9 the button goes off screen.


    Image 3:
    In theory it is still anchored at top right corner but this is not the desired result.


    Am I missing something trivial here?
    Thanks in advance,
     
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    What if Button wasnt a child of CatImage?

    did you try making a parent container and placing CatImage and Button in that?
     
  3. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    84
    Yes, but in that case the button will anchor to the container as the size of the 'cat image' varies according to resolution.
     
  4. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    ahhh.. Preserve Aspect isnt enough it seems. It be nice if you could lock either the width, or the height, to an aspect ratio, and it would auto size the other. :p
     
  5. FlyingSquirrels

    FlyingSquirrels

    Joined:
    Sep 18, 2015
    Posts:
    84
    There must be a way... any ideas/thoughts are appreciated.

    Thanks.