- Home /
GUIStyle applying to all labels, even after I comment it out.
Hey, so I made a style to change font size, but it changes the font size of every label.
Worse, when I comment out the style in my script every thing stays changed, and I have to close and re-open Unity for the labels to reset to normal size.
function OnGUI ()
{
if ((PlayState == PlayStates.Splash)){
GUI.Label (Rect(300,20,1000,200),"Press Space to Play");
}
if ((PlayState == PlayStates.End)){
GUI.Label (Rect(300,20,1000,200),"Press Space to Play Again");
}
GUI.Label (Rect(300,40,1000,200),
"Round 1: " + round[0] + " Round 2: " + round[1]+ " Round 3: " + round[2]+ " Round 4: " + round[3]+ " Round 5: " + round[4]);
if ((PlayState == PlayStates.Splash)){
GUI.Label (Rect(605,20,1000,200),"Hold I to display Instructions");
}
var bigFont:GUIStyle = "label";
bigFont.fontSize = 30;
var timeRemainingString = timeRemaining.ToString("F2");
GUI.Label (Rect(300,90,1000,200), timeRemainingString, bigFont);
}
Comment
Best Answer
Answer by perchik · Jul 31, 2013 at 07:23 PM
I'm not as familiar with Javascript, but I have a hunch at what's going on.
When you get the GUIStyle (` var bigFont:GUIStyle = "label";`) I assume that gets the default Label style, which actually changes the default values.
What you need to do is pass in a new GUIStyle that you want to use (from the editor). Then manipulating that GUIStyle won't affect everything, just anything that uses that style
It was exactly that!
Just had to change it to this:
var skin = GUI.skin;
var bigFont:GUIStyle = GUIStyle(skin.GetStyle("label"));
bigFont.fontSize = 300;
Thanks!
Your answer