Referencing GUI Skin: Custom Style Elements

Hello All,

I am fairly new with Unity3D. I am currently working with GUI elements and trying to understand them better. I have a few questions about how I can reference Custom Style Elements within my scripts.

I have created a few different images based off of the default “guiSkin > Box > Normal > Background”. Unity reads them fine and tiles them as needed when plugging them in individually.

My question is…

If I would like to use three or 4 different box types can I do this through changing the Default GUISkin by adding Custom Style Elements and plugging in those 3 to 4 images?

If so how can I reference those custom style elements when positioning them within the script? I cannot find material that shows how to call a specific Element by itself.

I have looked into the GameTutorial.pdf which shows how to create an animated sequence in the GUI by using the Custom Style Elements but I would like to call them separate.

The reasoning for this (if it makes any sense) is to work within a template based system for proper optimization and resolution scaling. I am using the boxes to overlap one another along “Z” for design purposes. Ill be dressing the UI up with separate GUITextures for those extra details but the overall menu system will consist of the template buttons and boxes.

Any help is greatly appreciated.

var HUDLeftStyle : GUIStyle;
var HUDCenterStyle : GUIStyle;
var HUDRightStyle : GUIStyle;

Adding style declarations like above will expose them in the inspector. At that point, change them however you want. Background color, texture, font, alignment, etc.

Once that’s all done, you simply reference the style within the GUI element itself.

GUILayout.Label("Score " + gameScore.ToString(), HUDCenterStyle);

If you look at the various overrides for the GUI elements in the docs, usually the last 3 or so contain a GUIStyle as a parameter.

Thank you, much appreciated. This will help a ton. Any other tips or tricks for Resolution Scaling? I know the Matrix is best but if there are any tutorials that you could link. I would love to check that out to.

I’ve read a few sections of the forum about GUI textures and GUI texts and just wanted to know why you want to stay away from them or limit the use? and if not then what is the best way to contain these objects? Within a gameObject, it being the parent or through code guiGroups?

The 3d platformer tutorial in the Unity website’s resources section deals with scaling your GUI.

I believe things such as GUItext have been depreciated, being part of the pre 2.0 GUI system. That’s why you see people suggesting to avoid them. Look at using Labels for both your textures and your text.

Your ‘container’ issue goes away when using the new GUI system as well, as it’s all done in code. What I generally do is have one GameManager script that drives my GUI along with the state machine for the game… Doing it that way everything is all self-contained and not spread out all over the place, with the additional performance benefit of only one OnGUI() call.