- Home /
Using a custom style of GUI.skin
I've read at least 5 posts about this subject, but they didn't have the right answer to solve it. Therefore I make this post.
My problem is as follows: I have a GUISkin used for my menu's. If I have the following OnGUI function, the time is displayed correctly:
void OnGUI ()
{
GUI.skin = skin;
GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer);
}
However, after I made a custom style called "Time_Label", I wrote this code:
void OnGUI ()
{
GUI.skin = skin;
GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, skin.GetStyle("Time_Label"));
}
And now the time doesn't get displayed. What's wrong?
$$anonymous$$y skin is nothing special. Just added a GUISkin. $$anonymous$$y style is also not complicated. The name is Time_Label. I added a color to the normal tab. I used the font Arial and font size = 40. This all is correct I think, or not?
Answer by MichaelARoberts · Oct 07, 2014 at 09:36 PM
Your should put GUI before skin.GetStyle ("Time_Label"));
Something like this:
GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, GUI.skin.GetStyle("Time_Label"));
But, I wrote 2 lines above: GUI.skin = skin. So that should do the trick, right?
it is still better to comprehend.
You can also use the string name of the style directly :
GUI.Label (new Rect (10, 40, 400, 400), "Time: " + currTimer, "Time_Label");
Answer by Tourist · Oct 08, 2014 at 09:57 AM
Try to get the style the line above and check if the style is null.
If it is null, then there is a mismatch on the name. Check there is no space in the name that could cause that. If not, the problems are in the parameters of your style.
Answer by Earless · Oct 08, 2014 at 10:20 AM
Everyone, thanks for answering. Apparently I'm very stupid. The alpha value of my colors were 0, so it worked, but the text was invisible :(
Again, thanks :)
Your answer
Follow this Question
Related Questions
Access custom style from skin via string 1 Answer
GUI works fine in editor, but not in build 2 Answers
GUIStyle returning error (error inside) 1 Answer
Optimizing OnGUI - Too many gui elements? 2 Answers
Changing OnGUI Texture to be behind another (GUI Rendered off of same script, different instance) 2 Answers