public static void Label (Rect position, string text);
public static void Label (Rect position, Texture image);
public static void Label (Rect position, GUIContent content);
public static void Label (Rect position, string text, GUIStyle style);
public static void Label (Rect position, Texture image, GUIStyle style);
public static void Label (Rect position, GUIContent content, GUIStyle style);

参数

position屏幕上用于标签的矩形。
text要在标签上显示的文本。
image要在标签上显示的 Texture
content该标签的文本、图像和工具提示。
style要使用的样式。如果省略,则使用当前 GUISkinlabel 样式。

描述

在屏幕上创建一个文本或纹理标签。

标签不与用户交互,不捕捉鼠标点击操作,并始终以正常样式呈现。若要创建对用户输入提供视觉响应的控件,请使用 Box 控件。

示例:绘制经典的“Hello World!”字符串:

\ 游戏视图上的文本标签。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnGUI() { GUI.Label(new Rect(10, 10, 100, 20), "Hello World!"); } }

示例:在屏幕上绘制纹理。除了字符串,标签也可用于显示纹理,只需传入纹理即可:

\ 纹理标签。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Texture2D textureToDisplay;

void OnGUI() { GUI.Label(new Rect(10, 40, textureToDisplay.width, textureToDisplay.height), textureToDisplay); } }