How would I support different screen sizes, Unity - unity3d

I'm trying to get it so that my buttons and UI will resize with the screen size that the game is playing in.
How would I do this?
What I have on my canvas:

Firts of all, you have to select on hierarchy the canvas that you want to resize depending the screen size. Then in the inspector you will go to "Canvas scaler" and in UI scale mode you select "Scale with screen size"

Related

Unity UI with different screen sizes

I am making a game and have a problem with UI. I made it to scale with the screen size. In 16:9 it looks as I want to:
UI is where I want it to be.
But when I switch to 2160 x 1080 I have a problem.
My UI is outside my game screen
I want that my UI on 18:9 stays in the same position as in 16:9. Any solutions to make it stay inside game bounds?
Canvas object -> Canvas Scaler component:
Scale With Screen Size
Match = 0 (0 for vertical app, 1 for landscape)
And then you need to change anchors for ui objects to align not from borders, but from center.
If you want UI to cover entire page make sure you hold shif + alt and select the stretch preset Unity will always cover the entire screen irrespective to resolution
Unity anchor preset
refrence

How to change canvas' size in unity3d

I can not change canvas' size when it's in Screen Space - Overlay Mode; After some research I found that the size of a canvas is determined by your game's screen size. The canvas just covers your screen. So I think I could change my camera's size to change canvas' size. But it does not work. Does anyone know how to set a specific size to a canvas?
So may be my question should be how to change the screen size showed
in editor?
To change the screen size, go to the Game window (accessed by the menu "Window->General->Game"). At the top of the window will be a screen size menu (outlined in green, below) to change the screen size. When pressed, it will display the list of screen sizes that will be emulated. I say "emulated" instead of "displayed" because it is possible to have a screen size larger than the screen on which you are working. It is also possible to zoom into a screen. The "Scale" slider (to the right of the screen size menu) will allow you to scale up/down.
As a note, the list of screens and resolutions shown are related to the current build target (accessed by "File->Build Settings..."). For example, common iOS screen sizes are displayed in the list when the build target is iOS.
Use the Canvas Scaler Component
Unity3D Documentation: Canvas Scaler

Unity - Keeping UI centered no matter the screen resolution

I want to keep my UI looking the same no matter which resolution the screen is at I am running of 16:10 in my game view and I want the UI to stay the exactly the same and centered even if the screen resolution changes.
Screenshot of UI
For the UI in the screenshot, I assume you want it always at the bottom of the screen and always the width of the screen.
For always taking up the width of the screen, select your canvas and go to its canvas scalar component. 'Change UI Scale Mode' to 'Scale with Screen Size' and adjust Reference Resolution to a resolution that looks good for you. Then the canvas elements will be the same width on all resolutions.
For always staying centered at the bottom of the screen, select the UI elements themselves, or their parent if they have one. Change their anchor to bottom center.
For more information about how to design for all screen resolutions, check the documentation as Hellium suggested!

Canvas size confusion in 2d game

I'm doing a 2D game and I'm new in unity.
How should I setup my Canvas for UI or Menu? I Mean what size they should be? Suppose If I add a Canvas with size of 1920x1080, what will happen when I build and run to a device with a resolution much less or higher than that?
Second question: If I force my game to open just Horizontally what will happen to those device which doesn't support changing Orientation?
regards
If you click on Canvas in your hierarchy, you can find a property "Canvas scaler" in the inspector. Change the "UI Scale Mode" to "Scale with Screen Size" and Set "Screen Match Mode" to 0.5

Canvas too big for the camera in Unity

I have created a 2D game with an orthogonal camera and using 16:9 display size.
I dragged my background image onto the hierarchy (it's about 2048x1152) and then set the camera size to be 22.5, which made it fit the background perfectly and displays just right.
However, when I add a Canvas for a UI it is absolutely giant, about 100 times bigger. It only becomes 'normal' size with respect everything else added when I set the camera to its default size of 5. So when I add a small graphic, it too becomes giant.
I'm simply following a book I read and I'm not doing anything to deviate.
Am I doing something wrong? Below is what I mean. The background image is the little image in the bottom right and the outlined rectangle is the canvas with a small graphic added.
Thanks.
To force your Hierarchy Canvas UI to the same resolution as the Camera View in your Unity Editor Scene window resolution (i.e. not ridiculously massive), or in other words get the Canvas to fit into the Camera size in the Scene, do the following:
Set the Canvas component's Render Mode to Screen Space - Camera.
Make sure you select or drag the relevant Camera from the Hierarchy to the Render Camera field in the Inspector.
You should use the Unity canvas for this along with the canvas scaler component. If I'm not mistaken it will scale all elements relative to the screen they are viewed on.
The canvas scaler allows you to match the scaling based on a preferred viewport size which is a life saver.
However this may not fit you needs perfectly as it would mean that the background element would become fixed. So if you wanted to pan the element you would need to move it's x and y elements within the canvas.
Hope that helps?