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?

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"));

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.

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 :frowning:

Again, thanks :slight_smile: