- Home /
Vertical Text
Hey everyone,
Try as I may, I just can't seem to find an answer to the following question - is there a way to display text vertically instead of horizontally (from within the GUI or OnGUI settings)?
Example:
"Hello World"
"
H
e
l
l
o
"
I'm trying to set up a screen of text in Japanese and I need it to display vertically (running from right to left) is possible.
Any ideas?
Do you want it the letters to be horizontal but words vertical or do you want to rotate the word so the whole thing is vertical?
I'd like the letters to remain horizontal but the words / sentences to be aligned vertically. $$anonymous$$ind of like the hotel sign in this picture here. → http://bit.ly/qF4Gb5
Answer by BlacKatFever · Oct 05, 2011 at 09:33 AM
I ultimately converted a word file into a texture and applied it to a plane. Was an awkward, time-consuming process but it got the job done. The scripts above were both informative and creative, but didn't mesh well with the Japanese language. Thanks for the suggestions!
Answer by Eric5h5 · Sep 01, 2011 at 10:13 AM
You'd make a function for doing so. As a quick example,
function OnGUI () {
GUILayout.Label(VerticalText("Hello"));
}
function VerticalText (input : String) : String {
var sb = new System.Text.StringBuilder(input.Length*2);
for (var i = 0; i < input.Length; i++) {
sb.Append(input[i]).Append("\n");
}
return sb.ToString();
}
Ideally you'd want to preprocess the text, rather than converting it over and over like that every frame.
Answer by Rennat · Sep 01, 2011 at 07:15 AM
I don't know of a built in way to do this but I would loop over the input string as an array and make smaller arrays for each column (you can pick an arbitrary row count for a column or do some math with the screen height and font size) then set up your GUI as follows
GUILayout.BeginHorizontal()
// loop over columns with
GUILayout.BeginVertical()
// loop over characters in a column with
GUILayout.Label()
GUILayout.EndVertical()
GUILayout.EndHorizontal()
Probably not the most efficient way of doing this but it's what I can think of off the top of my head.
If you instead want to rotate the whole thing (characters included) check out GUI.matrix which is lacking thorough documentation but a good example can be found in this post by Hanford Lemoore
Just realized I'm not sure how GUILayout.Label will react to just a space between words, you may have to use a conditional and use GUILayout.Space when you run across a space character
I'll give this a try, but with the sheer amount of text that we'll be using (it's basically a novel / game-type of project), I'm not sure that will be a feasible method outside of the bite-sized prototype we're making.
Seems like my other alternative is to do the whole thing up in some word processing program, convert it to an image file and then stick it on an in-game object. sigh
Thanks for the input, though, will definitely give it a try.
Going to leave this thread open a little while longer to see if there any other suggestions. :D
Yea it's probably not the best way to do it but it should work in a scroll area and you can always abstract the logic into a function that just takes the input string and makes all the GUILayout calls. Then just call the function in OnGUI where you need it.
Definitely keep looking for a better way of doing it and update us when you find it to help the next person that runs into it.
Answer by smoketh · May 13, 2020 at 07:14 AM
There is a better method.
https://github.com/Unity-Technologies/UnityCsReference/blob/3c2fbfebd60cd91d91c82a8b32ae26281687544d/Editor/Mono/Inspector/PhysicsManagerInspector.cs#L40 Straight out of C# referrence - what they do is they use GUI.matrix to rotate the text on its side. it's an elegant solution which provides least amount of headache.
Not only is GUI.matrix a headache in itself, it also will not produce the result OP asked for.