Okay I have three questions about Unity’s built in GUI. Can you layer gui? If so, how do you do it? Can you change the color of rectangles and other gui features? If so, how? And finally can you change the color of gui words? If so, how. Thank you to anybody who can answer this questions.
If you show me any script,please make it in C#, it doesn’t have to be ,but it would be great if it is.
Unity GUI is an immediate mode GUI. It draws controls in the order that they appear in your code. So if you want a label and then a button on top of it, both taking up the whole screen:
Rect rect = new Rect(0, 0, Screen.width, Screen.height);
GUI.Label(rect, "This is a label.");
if (GUI.Button(rect, "A button")) {
Debug.Log("Button was pressed.");
}
You can get more complicated by using GUI.Window and GUI.BeginGroup, and have Unity automatically lay out your controls using GUILayout. There’s a lot more information in the GUI Scripting Guide and code examples in GUI Basics.
Yes. GUI controls use GUIStyles. You can create a GUIStyle in code, but typically you’ll create a bunch of GUIStyles in a GUISkin through the inspector. Here’s a tutorial on Creating Custom GUI Skins. Then you just add the style in the parameter list of your GUI methods:
GUIStyle myCustomStyle = new GUIStyle(GUI.skin.label); // Manually create a new style based on the basic label.
myCustomStyle.normal.textColor = Color.red;
GUI.Label(rect, "This is a label in a custom style.", myCustomStyle);
Yes, in addition to using GUIStyles as mentioned above, you can use Rich Text. Your GUIStyle needs to be rich text enabled. If you’re editing a GUISkin, there’s a checkbox for this.
GUI.Label(rect, "<color=yellow>Yellow</color> and <color=blue>blue</color> make <color=green>green</color>.");
The current Unity GUI has a reputation for being slow, but it’s been used successfully in mobile titles on hardware that doesn’t have a lot of power, so it’s really a matter of learning how to use it efficiently. As you learn to use it, expect to rip out your first implementation as you pick up tips on getting it to run more efficiently.
I can’t thank you enough!
Happy to help!