GUI.RepeatButton

Switch to Manual
public static bool RepeatButton (Rect position, string text);
public static bool RepeatButton (Rect position, Texture image);
public static bool RepeatButton (Rect position, GUIContent content);
public static bool RepeatButton (Rect position, string text, GUIStyle style);
public static bool RepeatButton (Rect position, Texture image, GUIStyle style);
public static bool RepeatButton (Rect position, GUIContent content, GUIStyle style);

Parameters

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

Returns

bool 当用户单击该按钮时,返回 true。

Description

创建一个只要用户按住就一直处于激活状态的按钮。

// Draws 2 buttons, one with an image, and other with a text
// Prints a message when they get clicked.

// Prints a message when they get clicked.

using UnityEngine; using System.Collections;

public class Example : MonoBehaviour { public Texture btnTexture;

void OnGUI() { if (!btnTexture) { Debug.LogError("Please assign a texture on the inspector"); return; }

if (GUI.RepeatButton(new Rect(10, 10, 50, 50), btnTexture)) Debug.Log("Clicked the button with an image");

if (GUI.RepeatButton(new Rect(10, 70, 50, 30), "Click")) Debug.Log("Clicked the button with text"); } }