Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. We are looking for feedback on the naming of a new user research platform that we are working on.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Camera size and UI

Discussion in 'Scripting' started by JelleVos, Sep 11, 2020.

  1. JelleVos

    JelleVos

    Joined:
    Jun 21, 2015
    Posts:
    186
    Hi! I have a script that changes my 2d game camera orthographic size based on what aspect/resolution your playing the game on. The only problem is, my UI doesn't move with it. So how it is when I am playing on my default resolution:

    But when I change the resolution/aspect, my camera script scales the orthographic size good but the UI doesn't go with it:



    How can I fix this?
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    5,541
    If your UI is built off the canvas UI system, you should look into how your canvas scales with the screen size and you may have to adjust your anchoring on the UI elements.
     
  3. VishwasGagrani

    VishwasGagrani

    Joined:
    May 12, 2018
    Posts:
    75
    You can have two cameras. First camera (orthographic) will show the UI . Another camera ( orthographic or perspective ) will show the game. The UI camera will overlay the game camera.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    9,770
    You can achieve this fully with regular UI and anchoring, no extra UI cameras or silliness like that needed. Extra cameras will get you nothing but extra bugs here.

    Question: do you want the shape of the playfield to change when the aspect ratio changes? Or do you want it to be fixed aspect ratio and then contained within?

    To achieve various answers to the above, you can change the anchoring, change the Canvas Scaler "Screen Match Mode", use AspectRatioFitter and "fit in parent," and many other subtleties of UI design.

    Here is a key workflow hint: choose how you want it to fit, set the game view to that (say 4:3 aspect). Put all the pieces where you want.

    Now change the view to 16:9 aspect and note how they change. While at first it may seem mysterious, it will be 100% consistent based on anchors, scale modes, parent relationships, aspect ratios, etc. All of that affects it.

    You can even put anchors and AspectRatioFitters on certain sub areas of your UI to precisely control relative sizes.
     
  5. JelleVos

    JelleVos

    Joined:
    Jun 21, 2015
    Posts:
    186
    Thanks, this worked for me!
     
unityunity