Just putting a space into a string results in a space in any string you have, it won’t break anything.
If you talk about line breaks then create a new gui style that does not use wordwrap.
I’m aligning a GUIlabel to the right of the screen. If I end a string with a space, Unity automatically removes that space and the rest of the text shifts to the right in order to reflect this fact.
I’m using a custom text style with “word wrap” unchecked.
I’d like to keep the text style as it makes setting a background image so much easier. It doesn’t seem like a massive problem and that I’m sure there must be a solution which involves a “forced blank character”.
A visual aid:
(there’s actually a “.” after the first line, but it’s cut off in the pic)
I’m pretty sure that Unity GUI actually uses the trim calls on strings before using them to generate the bitmap rendering to prevent useless calculations for something that won’t show up yet would cause all sort of funny issues with auto alignement and guilayout.
Wouldn’t it be significantly easier and also more flexible to not use GUILayout and instead use GUI and specifying the corresponding rect? then you can just use an align right and have no probs at all and full control
Internally the text mesh generator ignores spaces at the end of a line for right and center aligned text (this is used for word wrapping so that spaces seemed stripped when text is wrapped on a space). To achieve this you should be able to use a unicode none breaking space as has been described above.
I’m getting this very problem - my gui works fine if I pad out the beginning of strings with N*“_” but not with N*" ". How can one insert multiples of non-breaking spaces into strings? In windows, using monodevelop. Alt +255 doesn’t work. Thanks for the help.
Necroing this to save someone else the frustration. Alt+0160 and Alt+0255 didn’t work for me, but putting “\r” after the spaces at the end of a string prevents Unity from stripping the spaces.
Could you please help me putting non breaking space into text field “text” value through GUI? I have a button name for example “My Button One” and when its width gets below certain threshold the text field on the button changes to:
“My
Button
One”
and I want to keep it:
“My Button One”
I tried with Horizontal and Vertical overflow options which keep the text like I want but doesn’t looks good for every resolution. I did get it to work and it works exactly like what I need by putting this in the script:
GameObject.Find(“MyButtonOne”).transform.GetChild(0).GetComponent().text = “My\u00A0Button\u00A0One”;
but the thing is I have plenty of buttons and it seems to be a bit overkill to have script changing your button names, besides I’d like to have real time feedback on how the buttons will look. Does anyone know how to achieve it in the Unity GUI typing in the “text” field on Windows? I read that on Mac it is Alt+Space. On Windows, I tried multiple combinations and non works.