Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Canvas scaler match width, align vertically?

Discussion in 'UGUI & TextMesh Pro' started by Zebbi, Aug 17, 2018.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    How do you have the canvas scaler align the UI to the middle of the window vertically, like the mainCamera does? For instance, when i try to resize the window, the UI is at the bottom:

    I'm using these settings:

    But i want the UI to match width and align directly underneath the game mainCamera, how do I set the position of this so it would resize like this:
     
  2. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    Not sure, but I think, since you use Scale With Screen Size scale mode, it will always stretch to the whole available screen.

    What I would do in your case is keep the scaler as it is, and change the position of your bottom panel, relative to the camera bottom position.
     
  3. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Ahh, I'm not sure how to do that since the canvas scaler takes over all of the rectTransform options?
     
  4. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    It's better to work with UI->Panels that are inside the canvas, rather than having the objects stay on the root canvas.
    You can move them freely inside the canvas.
    Shift your content to a Panel, or even an empty UI object that you can manipulate the RectTransform, and work your way through it.
     
  5. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    This is my canvas hierarchy:

    with canvas scaler on VerbsUI. Should I use another panel Ui between those sub items?
     
  6. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    Yes, right click your VerbsUI(root canvas, I assume) and click Create Empty.
    It will be in the same hierarchy level as Background, you can move your Background to it and then move the new object inside/outside the canvas area, by changing its RectTransform values.
    If you have any layout controller in the root canvas, you probably want to get rid of them and use them only in the objects under the canvas hierarchy, as they will possibly lock children position.
     
  7. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    That's working, I just can't seem to find a way of always anchoring it to underneath the maincamera. It might world using screen sace camera, but I can't reference maincamera in prefabs, and the interactions break with that setting.
     
  8. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    Unless you need your camera to move relative to an object's position and rotation, you should never make your camera be child or child objects. They should be root objects otherwise.