W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Unity 3D Toggle 控件
用于在屏幕上繪制一個開關(guān),通過控制開關(guān)的開啟與閉合來執(zhí)行一些具體的指定操作。
當(dāng)用戶切換開關(guān)狀態(tài)時,Toggle 控
件的繪制函數(shù)就會根據(jù)不同的切換動作來返回相應(yīng)的布爾值。
如選中 Toggle 控件
會返回布爾值 true
,取消選中就會返回布爾值 false
。
具體使用方法如下:
public static function Toggle(position:Rect, value:bool, text:string):bool;
public static function Toggle(position:Rect, value:bool, image:Texture):bool;
public static function Toggle(position:Rect, value:bool, content:GUIContent):bool;
public static function Toggle(position:Rect, value:bool, text:string, style:GUIStyle):bool;
public static function Toggle(position:Rect, value:bool, image:Texture, style:GUIStyle):bool;
public static function Toggle(position:Rect, value:bool, content:GUIContent,style:GUIStyle):bool;
注:
position
為控件顯示位置。
value
為默認控件是開還是關(guān)。
text
為控件顯示的字符內(nèi)容。
參數(shù)列表
參數(shù) | 描述 |
---|---|
position |
設(shè)置控件在屏幕上的位置及大小。 |
image |
設(shè)置控件上顯示的紋理圖片。 |
style |
設(shè)置控件使用的樣式。 |
text |
設(shè)置控件上顯示的文本。 |
content |
置控件的文本、圖片和提示小。 |
value |
設(shè)置開關(guān)是開啟還是關(guān)閉。 |
使用案例
GUI.Toggle
,保存場景。Assets
→ Create
→ JavaScript
命令,創(chuàng)建一個新的腳本文件。 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);
}
Ctrl+S
鍵保存腳本。Main Camera
上。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: