How do i fix the layout problem in unity? - unity3d

Im trying to build a replica of the game 'Breakout'.
when i build and run the game in unity it looks good and everything id the correct scale but when i build and run the project on my laptop all the elements change size and some of the elements dont change size and i am not sure if i have done anything wrong or if i have forgotten to do something to stop it from changing.
This is what the game looks like in the unity editor when playing the game:
And this is what it looks like once i build and run the project on my computer:
My resolution is set to stand alone.
is there a way to get it to look like it does in the unity editor when i build and run it on my computer because that is what its supposed to look like.

These days, there are many different screen sizes, and resolutions.
My favorite solution is to use a reference resolution that can expand but never shrink. This allows you to have a safe zone that stays consistent across different screen sizes. For a generic case, you would use 16:9 aspect ratio, with the resolution of either 1280x720 or 1920x1080.
In Unity, on your canvas, modify the Canvas Scaler such that UI Scale Mode is set to Scale with Screen Size. Add your reference resolution, and set the Screen Match Mode to Expand.
In the Game tab you can preview what 16:9 looks like. You can try out other aspect ratios or resolutions.
For example, the iPhone 11 has a much wider resolution, so it expands horizontally. It's up to you to design your UI in a way that makes sense. You can either keep everything in the safe zone or align elements to the corners of the screen.

Related

How do i make a 3d game pixel perfect? so that there is no anti aliasing or other filtering applied

This is what the game looks like in the 'game' window in unity, which is what it should look like https://ibb.co/xjst4vw achieved by removing all lighting including ambient lighting.
And this is what it looks once built https://ibb.co/4RcbMv8
Why is there a haze in the border between colors? How do I get it to be pixel perfect?
The aspect ratio of the in editor display is 160x144
I have change the game resolution by going to >edit >project setting >player and changing the height and width to the right size
The camera is also passing to a render texture which is of the right size, with the filter mode set to point.
I cant figure out what is causing this. to my knowledge All lighting is turned off. It looks like some up scaling error or maybe some sort of anti-aliasing effect which has also been turned off everywhere i could find.
Does anyone have an idea about what might be causing this? thanks.
There is postprocessing window in unity where you can specify such things like antyaliasing and so on. I think that this will make your game pixel perfect.
Found the answer to my own question the resolution in the >edit >project setting >player >resolution and presentation need to be as high res as it can be so in my case for a 1920x1080 screen it should 1120,1008 which is 160x144 scaled up by 7.
Then send data from you're main camera to a render texture that is set to the resolution you want (in my case 160x144) and create UI canvas that takes up the whole screen and a raw image as a child. Then put the render texture you created in the texture.

How to scale unity UI for every device

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.

UI is shown too small in final (built) game

I'm a newbie to Unity and am learning. I've made my first game which is a simple platformer, along with a main menu. The game also has some text GUI elements. When I run it in Unity's built-in player, the GUI looks fine, but when I build the project and run the game using the .exe, the UI is scaled down.
I'm attaching some screenshots below to clarify this.
(As seen in Unity player)
(As seen in game)
Also, the game UI also looks scaled down:
(As seen in player)
(As seen in game)
I want the in-game UI to be exactly like the one seen in the Unity player.
How do I fix this?
The Canvas can be set to scale with different settings if you want it to be accurate you should choose:
-Scale With Screen Size
Using the Scale With Screen Size mode, positions and sizes can be specified according to the pixels of a specified reference resolution. If the current screen resolution is larger than the reference resolution, the Canvas will keep having only the resolution of the reference resolution, but will scale up in order to fit the screen. If the current screen resolution is smaller than the reference resolution, the Canvas will similarly be scaled down to fit.
1- Go to your Canvas and select the Scale With Screen Size option
2- After that, make sure that the Reference Resolution is the same as the Game Window resolution in your Unity layout, I leave here an example:
As you can see, the resolution set on my Game window is (1024x768) and the reference resolution of the Canvas too.

How can I change the screen size in Unity?

Currently I am working on a Unity project. I started it on version 2018.3.6f1. The other day I installed version 2019.3.0a2 and this changed the screen size so now I have a white background at each side.
If I try going back to the size I had using the scale tool, it does not work so what do you recommend to change my screen size correctly or change it to its original one?
Here is a representation of my problem:
https://imgur.com/a/QKl9kVr
This is related to a setting you can change from the top bar of the Game window, it effectively sets the screen size emulation within the editor to different values, it looks like you want to have 'Free' mode, but you can also check behaviours in any other resolution

Resolution issue when building the game

I am using the ViewportHandler script for Unity(https://github.com/dfsp-spirit/way2close/blob/master/Way2Close/Assets/Scripts/ViewportHandler.cs), to allow for my UI to appear the same in different resolutions. I am pretty sure that it was looking just fine and pretty much the same in all resolutions(with different quality graphics due to stretching, but that is fine).
I have opened up my project after a while and I am now noticing that while the game scene looks fine inside the editor, the UI elements change position for all resolutions when building the game.
I am attaching two screenshots to show the difference. The Editor one is the proper one where elements are aligned properly. The other one is when I am building the game and running it full screen.
The weird thing is that when building the game, every resolution displays the wrong way (as in picture 1). So the elements are actually resizing properly, but they are just in the wrong place for some reason and I really can't see why. Any ideas ?
(My Canvas is Screen Space - Overlay, Scale with Screen Size, Ref resolution is 2560/1440, Match width and height and ref pixels 100).
You don't need 3rd party scripts to achieve a constant size on different resolutions. Use the Canvas Scaler component on your canvas and set it to 'Constant Physical Size'. Unity should handle all the rest.
If images/sprites change position, try to change the anchor point to fit your needs.