- Home /
Having a lot of trouble with GUI scaling
I'm working on an old-style RPG for practice with Unity2D. Right now I am trying to simulate a dialogue box like you would see in any RPG.
My issue is that it seems no matter what settings I use, I cannot get the size of dialogue boxes and text to be consistent. Ideally, regardless of resolution I want the boxes to always occupy the same amount of space, and the font to always be the same size and laid out the same way.
I've tried playing with the Canvas Scaler options, adding Horizontal Layout Groups, Content Size Fitters and my lack of experience is just stomping me.
As an example, if you look at the newer game Cosmic Star Heroine, it handles the dialogue boxes and texts the way pretty much how I would want to. Even scaling the resolution up quite high, I can still make out how many pixels are in the font.
I'd like to get this working in the GUI before I even look at scripts, so I have a good idea of what settings I am playing with. If anyone could point me in the right direction, that would be amazing.
EDIT - For clarification of what I'm trying to do.
I made a basic canvas with a panel and a text component:
Canvas - http://imgur.com/JSmg2d9
Panel - http://imgur.com/p0b1Ijq
Text - http://imgur.com/ldAR5Fa
If I keep the aspect ratio at resolutions of 16:9, it works great and always looks the same. (At least close enough). Howeverm if I switch to a different aspect ratio, the text will jump around and words with move to different lines, etc.
16:9 - http://imgur.com/maeHeb5
4:3 - http://imgur.com/NjdqXOx
The text clearly is shifting around on different aspect ratios.
Answer by Finijumper · Jun 16, 2017 at 12:44 PM
I tried this out, and it did work for the most part but not exactly what I was ai$$anonymous$$g for.
Ideally when I change the resolution, if I had a line of text filling the first line of the text box, I would expect that same text to still fill that same first line. This method seems to shuffle the text around.
Set "$$anonymous$$atch" value to 0.5 so it will scale in both height and width, and Textbox property to Best fit. set $$anonymous$$ max font size.
@harrismak4 I see this does work really well as long as I keep the aspect ratio the same. What would I need to modify to make this work across different aspect ratios like 4:3?
All you have to do is the pivot and anchor settings..
GUI system uses "anchors" to control how gui elements (like buttons) scale in relation to their parent container.
Unity has a tutorial video on how to use the new "Rect Transform" component (where the anchors are configured) here: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.
@harrismak4 I updated my question with more information, as I still don't seem to be able to make any progress. I'm familiar with the anchors and how they work but the pivot seems like a non-issue in this case.
Your answer
Follow this Question
Related Questions
Multiple NPCs 1 Answer
Unity 5 GUI Buttons Won't Show When Built 0 Answers
Place UI element on pointer up position. 1 Answer
Find GUI Button and Assign Text 1 Answer
Why does my UI.text only update when I change weapons? 1 Answer