Everytime i added 3 spaces or more, it will messed up with GetScreenRect Result.
For Example with this codes:
var myGuiText1 : GUIText;
var myGuiText2 : GUIText;
function Start()
{
myGuiText1.text = "-0000Text10000-";
myGuiText2.text = "- Text2 -";
var r1: Rect = myGuiText1.GetScreenRect();
var r2: Rect = myGuiText2.GetScreenRect();
Debug.Log ("Text1 Width = "+r1.width+" Text2 Width = "+r2.width);
}
The result is:
Text1 Width = 95 (“-0000Text10000-”)
Text2 Width = 129 (“- Text2 -”)
When it’s clear that Text1 should be wider than Text2.
Is there any temporary solution for this ??
I attach the Project in case you guys want to check it out.
129924–4833–$texttest_165.zip (468 KB)
It’s only “clear” that Text2 is wider when you’re using a monospaced font where all characters are the same width like in your script editor. You’re likely not using such a font in your GUI and thus the “size” shown in your script editor isn’t the same as what’s being calculated.
HiggyB, thanks for the explanation
Actually both GUIText is using default settings, something like this:
Font = None (Font)
Material = None (Material)
X, Y, Z = 0.5, 0.5, 0
Scale = 1, 1, 1
Pixel Offset X, y = 0, 0
Anchor = Upper Left
Alignment = Left
Line Spacing = 1
Tab Size = 4
Pixel Correct = True
Is the default font not considered as monospaced ?
i wonder how come the width of the text differ so greatly though,
another example is, when i keep adding 3 or 4 spaces inbetween word, i have a text that should be around 1200 width but it show as around 10000 width :shock:
the GUIText.text is somewhat like this:
myGuiText1.text = " A B C D E F and so on...";
thanks a gain in advance for the explanation.
Fonts aren’t “considered” monospace, they either are monospaced or they aren’t. And no, the default font used by the default GUI skin is not monospaced, you need to find one you like and explicitly use it if this is important to you.
Welcome to the world of fonts where the font creator uses their sense of artistic style to create the right look. Monospaced fonts remove part of that and have even spacing for all characters and script editors more often than not use monospaced fonts by default.
HiggyB, I did another test with a Courier Font, which is a Monospaced Font according to this:
And i can confirm that GetScreenRect() still giving a “bigger than it should” number… when i type more than 3 spaces.
for Example :
Text = " A" will result = 160
Text = "A E" will result = 90
Text = "0000A" will result = 50
Text = "AAAAA" will result = 50
Text = "ABCDE" will result = 50
so yeah… for now i just count the length of the text and multiply it with 10 to get the text width instead of using GetScreenRect() (But i still need to use a monospaced font like your suggestion).
Ok, now that sounds like a bug! That’s for working it into my head here, please log it via the Help menu so we have it noted. Thanks!
ok, roger that, report bug right away 8)