GUI.Toggle 开关按钮

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

Parameters参数

Returns

bool - The new value of the button.

返回bool类型,按钮的新值。

Description描述

Make an on/off toggle button.

创建on/off开关按钮,也就是类似通常说的单选按钮。

另见: SetNextControlName, GetNameOfFocusedControl.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Texture aTexture;
	private bool toggleTxt = false;
	private bool toggleImg = false;
	void OnGUI() {
		if (!typeof(aTexture)) {
			Debug.LogError("Please assign a texture in the inspector.");
			return;
		}
		toggleTxt = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
		toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
	}
}
var aTexture : Texture;

private var toggleTxt : boolean = false;
private var toggleImg : boolean = false;

function OnGUI () {
	if(!aTexture) {
		Debug.LogError("Please assign a texture in the inspector.");
		return;
	}
	//绘制两个开关控件,一个是文本,一个是图片
	toggleTxt = GUI.Toggle(Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
	toggleImg = GUI.Toggle(Rect(10, 50, 50, 50), toggleImg, aTexture);
}
Page last updated: 2011-6-14