GUI.Button 按钮

static function Button (position : Rect, text : String) : bool
static function Button (position : Rect, image : Texture) : bool
static function Button (position : Rect, content : GUIContent) : bool
static function Button (position : Rect, text : String, style : GUIStyle) : bool
static function Button (position : Rect, image : Texture, style : GUIStyle) : bool
static function Button (position : Rect, content : GUIContent, style : GUIStyle) : bool

Parameters参数

Returns

bool - /true/ when the users clicks the button

当用户点击按钮的时候返回true。

Description描述

Make a single press button. The user clicks them and something happens immediately.

创建一个单次按下按钮。用户点击按钮事件立即触发。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Texture btnTexture;
	void OnGUI() {
		if (!typeof(btnTexture)) {
			Debug.LogError("Please assign a texture on the inspector");
			return;
		}
		if (GUI.Button(new Rect(10, 10, 50, 50), btnTexture))
			Debug.Log("Clicked the button with an image");

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

	}
}
//绘制2个按钮一个有图像,另一个是文本
//当按钮被点击的时候打印信息
var btnTexture : Texture;
function OnGUI() {
	if (!btnTexture) {
		Debug.LogError("Please assign a texture on the inspector");
		return;
	}
	if (GUI.Button(Rect(10,10,50,50),btnTexture))
		Debug.Log("Clicked the button with an image");
	if (GUI.Button(Rect(10,70,50,30),"Click"))
		Debug.Log("Clicked the button with text");
}
Page last updated: 2011-1-14