- Home /
Unity 5 UI GUI Text Canvas Screen Resolution Adaption Problem
Hi, I want to have a UI Text with Canvas child (which is default). I would like it to be that when the screen resolution changes, it also fixes the text to fit. So, for short, for the text to fit any sized computer screen. I am making a main menu. Here are some pictures:
file:///C:/Users/anthony/Pictures/Screenshots/Screenshot%20(4).png file:///C:/Users/anthony/Pictures/Screenshots/Screenshot%20(5).png
The first one is full screen. The second one is a smaller screen. (Note how you can't see the text. The text is still there.) My goal is to be able to see the text even in the small screen. I am open to script(C# if possible) and also configurations (ex: Components) Whatever works. If you do provide script, please explain what object to attach it too as well as description. Thank you.
Answer by DiegoSLTS · Mar 19, 2015 at 12:08 AM
Don't do what you suggested, is a really unflexible way of doing what you want.
Checkout the "UI scale mode" property of the Canvas Scaler component in your Canvas game object. It defaults to "Constant pixel size", a really bad option if you aim to more than one resolution, a window of 640x480 will only show a 640x480 rectangle from the top left corner of your canvas.
Change the UI scale mode to "Scale with screen size" and unity will shrink or expand your Canvas to best fit in your screen.
Answer by whiteant54 · Mar 18, 2015 at 11:55 PM
FOR ANYONE WHO HAS THE SAME PROBLEM, LISTEN CLOSELY. ALL YOU NEED TO DO IS: Canvas -> "Your Text" -> Settings sign on the top right -> Reset
Then Under Rect Transform You: Anchors -> Min X: 0, Min Y: 0.5, Max X: 0, Max Y: 0.5
Then You: Pivot X: 0, Pivot Y: 0.5
When you do so, the top left square in rect transform should say on top: Left, and on the side: Middle. Then you may move your text/buttons anywhere you like. (Note: Anywhere in the canvas.) Make sure your Scale is X: 1, Y: 1, Z: 1. To resize your text, use the font controller. If you follow my instructions, when you play your game, (in the editor to test) you should be able to change the ratio from your game view to Free aspect, 5:4, 4:3, etc without losing view of your GUI text/buttons/image/etc. (PLEASE NOTE: Maximize on play MUST be selected.
Hope this helped since I know this is a big problem and I even had this problem myself.
Happy developing :)