The question is answered, right answer was accepted
Change font-size according to resolution
I am currently developing a game off of a tutorial, the game is called laser defender and your goal is to shoot down enemies. The game seemed to be working fine in the inspector, but when I did a build of the game, and set my resolution to my computer's resolution, this happened:
The text was tiny and some of the buttons would not work, Is there a way to fix this? I still pressed the play button, and the enemies seemed to be the same size, and were still working fine, one the UI elements were messed up.
if you could show me a way to fix this, it would be great! Thank you!
Answer by Ali-hatem · Apr 11, 2016 at 12:18 PM
in cnavas make sure Canvas Scaler is Scale With Screen Size se doc Canvas Scaler
I do agree with that solution !
Then it will look as it looks in the game window in Unity, whatever the resolution is. For a future project brows your Game Window resolution through all the different resolution to make sure your UI will always have the desired aspect. You should work in "Standalone" or X:Y resolution in your Game window ins$$anonymous$$d of "Free Aspect"
Answer by pradeepBee · Apr 11, 2016 at 11:12 AM
You can check 'BEST FIT' checkbox for the text fields in inspector to fix this.
That is not correct. Best fit will not automatically scale elements according to screen resolution.
Thanks for the reply. I gave the best fit option to adjust the text size in the text fields.
Indeed, it will maximize the text size IN THE TEXTBOX. If your textbox is very small (like in your screenshot) you need to ajust the size of the text element and THEN use best fit.
Answer by KaushikRahul · Apr 11, 2016 at 12:23 PM
You can set your Canvas' "UI Scale Mode" under "Canvas Scaler" to "constant physical size"
it makes the UI elements maintain their original size. so they remain the same size even if the resolution changes.
and then you can use "Best Fit" for Text component which will make it appear better on the screen.
Thank you for your comment! it worked, Thank you soo much! I am having one other problem though: when I change "UI Scale $$anonymous$$ode" to "constant physical size", it changes all of the buttons that i have to big Xs, making me redo all of them, is there a quick way to fix this?
Thank you
There is on more way you can do it.
Set your Canvas' "UI Scale $$anonymous$$ode" to "Constant Pixel Size"
then on the text or button or whatever you want to place just change the "Anchor Presets" as per your need.
i tried uploading the screens, but am not being able to. Some Unity's website issue.
Sorry.
Yes, change it to "scale with screen size." You don't have to redo all your buttons.
Constant Physical Size keeps the same overall size even if the screen gets to small. Hence the name and it is useless for your task.
Constant Pixel Size is essentially the same and also useless for your task.
Use Scale with Screen Size and type in your desired apect ratio (16:9, 4:3 16:10 etc..) This way your elements will look the same on a 100" tv monitor and a 3" smartphone screen.
PS: If you don't want to set the reference resolution to small values like 16:9, use the full equivalent resolution, like 1600x900 or 1920x1080. Some people prefer it this way, but there is literally no difference since they are all the ratio 16:9.
@Le Pampelmuse that's what i suggested but with your explanation hop it's clearer now & i wish from those whom not sure about there answers to test in unity before misleading others .
Hi, this has worked really well in my previous project, but when I tried it in my new project, it wouldn't work. I tried to put a image on here but it wouldn't upload. Essentially it looked like my project was in the middle of the screen, and a bunch of black space was to the left and right of it. Is there a way to fix this? I also noticed that the UI elements are fine on any resolution if the game is windowed. Is this a glitch in unity [I have tried getting 4.3.4], or could it be a setting that I have not checked [I created a new project, so there might be something unchecked by default]. If there is a way to fix this, please tell me, Thank you!
Add on:
I tried to mess around with it a little more, and i found out that the smaller the resolution, the smaller the black space. At the resolution of 1920X1080 the black space is completely gone. I have never had this problem before, this happens with "constant pixel size" and "scale with screen size".