GUI Styles are a collection of custom attributes for use with IMGUI. A single GUI Style defines the appearance of a single IMGUI Control.
If you want to add style to more than one control, use a GUI Skin instead of a GUI Style. For more information about IMGUI, please read the GUI Scripting Guide.
Please Note: This page refers to part of the IMGUI system, which is a scripting-only UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary system. Unity has a full GameObject-based UI system which you may prefer to use. It allows you to design and edit user interface elements as visible objects in the sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary view. See the UI System Manual for more information.
Property: | Function: |
---|---|
Name | The text string that can be used to refer to this specific Style |
NormalThe direction perpendicular to the surface of a mesh, represented by a Vector. Unity uses normals to determine object orientation and apply shading. More info See in Glossary |
Background image & Text Color of the Control in default state |
Hover | Background image & Text Color when the mouse is positioned over the Control |
Active | Background image & Text Color when the mouse is actively clicking the Control |
Focused | Background image & Text Color when the Control has keyboard focus |
On Normal | Background image & Text Color of the Control in enabled state |
On Hover | Background image & Text Color when the mouse is positioned over the enabled Control |
On Active | Properties when the mouse is actively clicking the enabled Control |
On Focused | Background image & Text Color when the enabled Control has keyboard focus |
Border | Number of pixelsThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info See in Glossary on each side of the Background image that are not affected by the scale of the Control’ shape |
Padding | Space in pixels from each edge of the Control to the start of its contents. |
Margin | The margins between elements rendered in this style and any other GUI Controls. |
Overflow | Extra space to be added to the background image. |
Font | The Font used for all text in this style |
Image Position | The way the background image and text are combined. |
Alignment | Standard text alignment options. |
Word Wrap | If enabled, text that reaches the boundaries of the Control will wrap around to the next line |
Text Clipping | If Word Wrap is enabled, choose how to handle text that exceeds the boundaries of the Control |
Overflow | Any text that exceeds the Control boundaries will continue beyond the boundaries |
Clip | Any text that exceeds the Control boundaries will be hidden |
Content Offset | Number of pixels along X and Y axes that the Content will be displaced in addition to all other properties |
X | Left/Right Offset |
Y | Up/Down Offset |
Fixed Width | Number of pixels for the width of the Control, which will override any provided Rect() value |
Fixed Height | Number of pixels for the height of the Control, which will override any provided Rect() value |
Stretch Width | If enabled, Controls using this style can be stretched horizontally for a better layout. |
Stretch Height | If enabled, Controls using this style can be stretched vertically for a better layout. |
GUIStyles are declared from scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary and modified on a per-instance basis. If you want to use a single or few Controls with a custom Style, you can declare this custom Style in the script and provide the Style as an argument of the Control function. This will make these Controls appear with the Style that you define.
First, you must declare a GUI Style from within a script.
/* Declare a GUI Style */
var customGuiStyle : GUIStyle;
...
When you attach this script to a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary, you will see the custom Style available to modify in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary.
Now, when you want to tell a particular Control to use this Style, you provide the name of the Style as the last argument in the Control function.
...
function OnGUI () {
// Provide the name of the Style as the final argument to use it
GUILayout.Button ("I am a custom-styled Button", customGuiStyle);
// If you do not want to apply the Style, do not provide the name
GUILayout.Button ("I am a normal IMGUI Button without custom style");
}
For more information about using IMGUI, please read the GUI Scripting Guide.
GUIStyle
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.