public static bool Button (Texture image, params GUILayoutOption[] options);
public static bool Button (string text, params GUILayoutOption[] options);
public static bool Button (GUIContent content, params GUILayoutOption[] options);
public static bool Button (Texture image, GUIStyle style, params GUILayoutOption[] options);
public static bool Button (string text, GUIStyle style, params GUILayoutOption[] options);
public static bool Button (GUIContent content, GUIStyle style, params GUILayoutOption[] options);

参数

text要在按钮上显示的文本。
image要在按钮上显示的 Texture
content该按钮的文本、图像和工具提示。
style要使用的样式。如果省略,则使用当前 GUISkinbutton 样式。
options(可选)一个布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

返回

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

描述

创建一个单击按钮。

创建一个可以像普通按钮一样按下和释放的 Button。 当释放该 Button 时, Button 返回预期的 true 值。如果将鼠标移离按钮,则不会单击该按钮。

\ 游戏视图中的按钮。

using UnityEngine;

public class ExampleScript : MonoBehaviour { // Draws a button with an image and a button with text Texture tex;

void OnGUI() { if (!tex) { Debug.LogError("No texture found, please assign a texture on the inspector"); }

if (GUILayout.Button(tex)) { Debug.Log("Clicked the image"); } if (GUILayout.Button("I am a regular Automatic Layout Button")) { Debug.Log("Clicked Button"); } } }