Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GUIContent.GUIContent

GUIContent()
GUIContent();
def GUIContent()

Description

Constructor for GUIContent in all shapes and sizes.

Build an empty GUIContent.

GUIContent(text: string)
GUIContent(string text);
def GUIContent(text as string)

Description

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"));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnGUI() as void:
		GUI.Button(Rect(0, 0, 100, 20), 'Click Me')
		GUI.Button(Rect(0, 30, 100, 20), GUIContent('Click Me'))

GUIContent(image: Texture)
GUIContent(Texture image);
def GUIContent(image as Texture)

Description

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));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public icon as Texture

	def OnGUI() as void:
		GUI.Button(Rect(0, 0, 100, 20), GUIContent(icon))

GUIContent(text: string, image: Texture)
GUIContent(string text, Texture image);
def GUIContent(text as string, image as Texture)

Description

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));
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public icon as Texture

	def OnGUI() as void:
		GUI.Button(Rect(0, 0, 100, 20), GUIContent('Click me', icon))

GUIContent(text: string, tooltip: string)
GUIContent(string text, string tooltip);
def GUIContent(text as string, tooltip as string)

Description

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);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnGUI() as void:
		GUI.Button(Rect(0, 0, 100, 20), GUIContent('Click me', 'This is the tooltip'))
		GUI.Label(Rect(0, 40, 100, 40), GUI.tooltip)

GUIContent(image: Texture, tooltip: string)
GUIContent(Texture image, string tooltip);
def GUIContent(image as Texture, tooltip as string)

Description

Build a GUIContent containing an image. When the user hovers the mouse over it, the global GUI.tooltip is set to the tooltip.

GUIContent(text: string, image: Texture, tooltip: string)
GUIContent(string text, Texture image, string tooltip);
def GUIContent(text as string, image as Texture, tooltip as string)

Description

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.

GUIContent(src: GUIContent)
GUIContent(GUIContent src);
def GUIContent(src as GUIContent)

Description

Build a GUIContent as a copy of another GUIContent.