static function Toggle (value : bool, image : Texture, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, text : string, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, content : GUIContent, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, text : string, style : GUIStyle, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : bool
bool - The new value of the button.
返回布尔类型,该按钮的新值。
Description描述
Make an on/off toggle button.
创建一个开关按钮。类似于单选按钮。
Toggle button in the Game View.
在游戏视图中的开关按钮
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 = GUILayout.Toggle(toggleTxt, "A Toggle text");
toggleImg = GUILayout.Toggle(toggleImg, aTexture);
}
}
// Draws 2 toggle controls, one with a text, the other with an image.
//绘制2个开关控件,一个带有文本,一个带有图像
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 = GUILayout.Toggle(toggleTxt, "A Toggle text");
toggleImg = GUILayout.Toggle(toggleImg, aTexture);
}