在iGUI中,Enable=false可以看不到控件,但是沒有去除,我今天和大傢說說unity動態添加刪除iGUI控件。
1.添加:iGUI.iGUIRoot.addElement("iGUIProgressBar");
2.去除:iGUI.iGUIRoot.removeElement(iGUI.iGUIElement);
下面看看我的例子吧:
[java]
<pre class="html" name="code">var root:iGUI.iGUIRoot;
var chun:iGUI.iGUIProgressBar;
function OnGUI() {
if(GUI.Button(Rect(0,0,100,100),"add")){
chun=root.addElement("iGUIProgressBar");//必須寫iGUIxxx;
chun.name="chun";
}
if(GUI.Button(Rect(0,110,100,100),"remove")){
root.removeElement(chun);//必須沒有“”,要不然報錯的。
}
}
註:removeElement的chun是var chun:iGUI.iGUIProgressBar;裡面的chun,而不是chun.name="chun";
我以前不會改變iGUIProgressBar的height,後來發現應該把Empty Style和Fill Style的–>Fixed Height改成0就可以瞭~~~
摘自 dlnuchunge的專欄