Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseConstructor for GUIContent in all shapes and sizes.
Build an empty GUIContent.
Build a GUIContent object containing only text.
When using the GUI, you don't need to create GUIContents for simple text strings - these two lines of code are functionally equivalent:
function OnGUI () { GUI.Button (Rect (0, 0, 100, 20), "Click Me"); GUI.Button (Rect (0, 30, 100, 20), GUIContent ("Click Me")); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void OnGUI() { GUI.Button(new Rect(0, 0, 100, 20), "Click Me"); GUI.Button(new Rect(0, 30, 100, 20), new GUIContent("Click Me")); } }
Build a GUIContent object containing only an image.
var icon : Texture;
function OnGUI () { GUI.Button (Rect (0, 0, 100, 20), GUIContent (icon)); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Texture icon; void OnGUI() { GUI.Button(new Rect(0, 0, 100, 20), new GUIContent(icon)); } }
Build a GUIContent object containing both text
and an image.
var icon : Texture;
function OnGUI () { GUI.Button (Rect (0,0,100,20), GUIContent ("Click me", icon)); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Texture icon; void OnGUI() { GUI.Button(new Rect(0, 0, 100, 20), new GUIContent("Click me", icon)); } }
Build a GUIContent containing some text
. When the user hovers the mouse over it, the global GUI.tooltip is set to the tooltip
.
function OnGUI () { GUI.Button (Rect (0, 0, 100, 20), GUIContent ("Click me", "This is the tooltip"));
// If the user hovers the mouse over the button, the global tooltip gets set GUI.Label (Rect (0, 40, 100, 40), GUI.tooltip); }
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void OnGUI() { GUI.Button(new Rect(0, 0, 100, 20), new GUIContent("Click me", "This is the tooltip")); GUI.Label(new Rect(0, 40, 100, 40), GUI.tooltip); } }
Build a GUIContent containing an image. When the user hovers the mouse over it, the global GUI.tooltip is set to the tooltip
.
Build a GUIContent that contains both text
, an image
and has a tooltip
defined. When the user hovers the mouse over it, the global GUI.tooltip is set to the tooltip
.
Build a GUIContent as a copy of another GUIContent.
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