- Home /
GUI: non-static text won't display on Mobile/Web player
Hello, my project uses GUI labels floating in a circular pattern around the player to display the relative directions of points of interest, kind of like a compass/radar display. For now the only element on display is the _name of the object, which is pulled and assigned randomly from a rather large text file.
GUI.Label(new Rect(x,y,Screen.width/5,Screen.height/5), _name);
The labels and attached text are all displaying without a hitch in the editor and the Windows build. The problem is that Web Player and Android will not render the text and over the past 9 hours I've tried all (of the very few) workarounds I could find on google without success.
The frustrating thing is that hard coded GUI elements are rendering without any problems:
GUI.Button (new Rect (0,Screen.height - Screen.height/5,Screen.width/5,Screen.height/5), "Dock")
All I've learned is that mobile doesn't support dynamic text, but I have no way of predicting which names will be generated so I can't set them before runtime.
Does anyone know of a possible solution short of stitching together alphabet textures to form a name based on the string value?
Answer by whydoidoit · May 21, 2012 at 08:16 AM
It sounds to me like you need to install a font on the device. If you are using the default font it will work fine in the editor, but will not work on the device.
The whole thing about dynamic fonts is that you cannot change the size of a font on the phone, but you can change the text just fine.
Create a font for each point size you need and then switch between then.
Hum, the fonts weren't the issue as all the standard text fields displayed properly, and replace _name with "Text" would display all the the labels and "Test" across all 3 platforms.
What you said about installing the font on the device got me thinking though, I'm getting my _names from a text file that's currently in my assets/resources folder.
I was under the impression that it would be compiled and added to the .apk that way, but it's possible that it's not being found by the device and all the strings are in fact null, that's why they're not showing.
I'll give you answer cred for the inspiration and pursue that train of thought in the morning, thank you.
Answer by Gennadios · May 22, 2012 at 06:36 AM
For the benefit of anyone that might be having these problems in the future, I have a working script that should be cross platform, tested on windows, web player, and Android:
void GenNames()
{
int rand = 0;
TextAsset textAsset = (TextAsset)Resources.Load("altplanetnames", typeof(TextAsset));
string ta = textAsset.ToString();
string[] names = ta.Split('\n');
foreach(Planet p in planets)
{
rand = Random.Range(rand, names.GetLength(0));
p.SetName(names[rand]);
}
}
I experimented with a few input reader types and Regex, none of them worked, TextAsset.ToString() and string.Split() got the job done.
Your answer
Follow this Question
Related Questions
Blurry Text using Textmesh Pro on android device 2 Answers
Speed of Gui Text vs 3D Text Mobile 1 Answer
Avoid auto device capitalization for textfields on mobile 1 Answer
How to make GUI text look good? 0 Answers
Problem Displaying Score on GUI text 0 Answers