How to scale unity UI for every device - unity3d

I'm trying to make a level select screen for my game, but when testing the game build the ui isn't scaled that well
I'm currently using the Canvas Scaler with the following settings
These settings give me..interesting results to say the least
What the result is SUPPOSED to be is this
How am I able to do this?

There a few things that you should keep in mind while building the UI for different screens.
Have a target Aspect ratio. Generally it should be 16:9 for landscape and 9:16 for Portrait.
Make sure the reference resolution is in line with your target aspect ratio.
Set the Match option of canvas scalar to 0.5 to scale evenly. If you are sure the device aspect ratio will change in only one direction then set either height or width. For example a portrait game will scale only by height if you switch from 9:16 to 9:18.(0.5 has worked always for me)
Select the aspect ratio in the game window and set the Anchors of the UI to the corner of the UI element. That way Unity will know where the element should be based on Canvas size.
Here is a video that demonstrates it
https://youtu.be/08S1VGL9afg

First of all, use some custom resolution in game view instead of Free Aspect.
Then you could try adjusting Match with Height or width to 0.5.
In some case, you have to adjust custom anchors using these little guys
If you want to absolutely preserve aspects, use this option on Image component.

Related

Unity gameobjects and text ui change size and position while changing resolution

sorry I have to put all of this as an image but I couldn't post this with text as when creating the original post something happened to where it was flagged as spam. I figured this would be the only way?
Unity's UI screen is different from the in-game world space.
For the UI part you can easily fix the issue of the size and position by considering the following:
First thing you need to check is the Canvas Scaler component which is automaticaly generated on your Canvas gameobject.
Canvas Scaler Example
First under The UI Scale Mode you should choose the "Scale with Screen Size" which will make UI elements bigger the bigger the screen is.
Second is the Reference Resolution which is the resolution the UI layout is designed for. If the screen resolution is larger, the UI will be scaled up, and if it's smaller, the UI will be scaled down. A good example is to set the dimensions int something like this (1920x1080) which is the most common landscape resolution.
Third is the Screen Match Mode which is a mode used to scale the canvas area if the aspect ratio of the current resolution doesn't fit the reference resolution. With other words if you change your in-game resolution this will handle your UI elements.
Fourth is Match which will determine if the scaling is using the width or height as reference, or a mix in between. So if your game is in landscape mode you should set it to 0, if it's in portrait mode you should set it to 1.
Last thing to keep in mind that will affect your UI elements position is the Anchor presets which is part of the Rect Transform component on each of your UI elements.

How to resize camera to work with multiple resolutions on Unity?

I'm working on a fun project on Unity and I want to support all mobile resolutions in landscape mode. I designed everything to work in 1920:1080 resolution.
Everything works in world space, including UI elements.
What's correct way of supporting all resolutions (including weird ones like square 1:1)?
I don't want the scene to be cropped or filled with blue, all I want is my camera's viewport to be scaled to fit the device screen. I don't care if objects in the scene will get thin or fat.
To support different aspect ratios for your UI Elements, I recommend making use of the anchors that come with every RectTransform. These will ensure that the position of an element is consistent across various aspect ratios. For example, setting the anchor of an element to be left on the x axis will make the origin and pivot on the far left. This means an x position of 10 will position the element 10 units away from the far left of the element's parent. This is made easier with Anchor Presets. Although you can set every value yourself, Anchor Presets provide an easier way to anchor your UI Elements. Provided you have a RectTransform on you UI Elements, every element should have the Anchor Presets available. No need to change the width and height of your Canvas.
Aside from that the Camera should automatically resize depending on the resolution of the game view. You can test how your elements' anchoring works with different aspect resolutions by setting your game view's Aspect to free aspect, which will change the aspect ratio of the game depending on game view's width and height.

UI designing for multiple resolution in Unity

Hi I am really new to Unity development.I have a canvas with following structure
Inspector for all the UI elements are as below
For canvas
For Panel
For Inner Button
I am checking this on my iPad pro 2020.Followings are the results.(The + button inside the panel). My question is the "+" button and panel's aspect ratio is different when changing from portrait to landscape. How can I fix this issue? Thanks in advance.
Portrait
Landscape
If you choose a canvas scaler type (width or height), should change dynamically with W/H ratio your device aspect ratio calculation as float value, also this value are related your device screen orientation. So you need to calculate seperately for portrait or landscape orientations. Differently you could use match mod with shrink and set value to minimum pixel ratio your sprites.
However, in some cases, you may need to create compatible image files in different resolution modes while designing for tablets.
These methods gives you a immutable screen visuals...
Also, if you haven't read it, please read this thread and the related instructions.
Multi Resolution

How do I make my 2D game responsive to different resolutions?

I making a 2D game in unity. And I want to make my game responsive to different resolutions, and when I use Canvas Scaler all my UI objects become very bigger.
if you can help please response.
thank you!
Designing UI for Multiple Resolutions
1. Using anchors to adapt to different aspect ratios
One way to keep buttons inside the screen is to anchor them to their respective corners,
One way to keep the buttons inside the screen is to change the layout such that the locations of the buttons are tied to their respective corners of the screen.
Once the buttons have been anchored to their respective corners, they stick to them when changing the resolution to a different aspect ratio.
When the screen size is changed to a larger or smaller resolution, the buttons will also remain anchored to their respective corners. However, since they keep their original size as specified in pixels, they may take up a larger or smaller proportion of the screen.
2. Scaling with Screen Size
In the Canvas Scaler component, you can set its UI Scale Mode to Scale With Screen Size. With this scale mode you can specify a resolution to use as reference. If the current screen resolution is smaller or larger than this reference resolution, the scale factor of the Canvas is set accordingly, so all the UI elements are scaled up or down together with the screen resolution.
The layouts will appear the same in different resolutions, only with a lower pixel density depending on if you scale up or down.
One thing to be aware of: It can be possible that some element are larger in landscape aspect ratio. This can be fixed if you change the Match property to 0.5 instead, it will compare both the current width to the reference width and the current height to the reference height now.
Unity Documentation

Unity3D: Aspect ratio issue

In Unity3D I can't scale the game properly to remove the black bar.
I've added pictures for reference:
EDIT: I need to make the canvas scale to the whole screen instead of only a part of the screen.
You should first set your game viewport to simulate the resolution and screen size of whatever you're building for. Change Free Aspect to the appropriate aspect ratio or manually add a new resolution.
Also, I believe the match mode you want for your Canvas Scaler is Match Width or Height.
You have to set anchors of Image to each corner of your canvas display so It can scale accordingly.
Just change the aspect ratio from 'free aspect' to '16:9' or manually enter an aspect ratio that suits your needs.
Cheers.
Try to dynamically spawn the background or image by using Scale To Fit lots of Unity Documentation to help with that so when compiled you can tend to get a stronger and fuller picture this may help with a general sizing issue
Set the screen resolution manually in the Start() of your code:
Screen.SetResolution(x, y, true)