2013-12-08 39 views
0

我想使按鈕激活另一個按鈕,然後一旦第二個按鈕被點擊,它將激活第三組按鈕。 感謝您的幫助提前。3組按鈕激活 - UnityScript for Unity

下面是UnityScript當前編碼:

var toggle : boolean; 

function OnGUI() 
{ 
    toggle = GUI.Toggle(Rect(335, 80, 50, 50), toggle, "Button1", "button"); 

    if (toggle && GUI.Button(Rect(335, 140, 50, 50), "Button2")) 
    { 
     // This is the part where I want the second button to activate and show the third set of button(s). 
     if (toggle && GUI.Button(Rect(335, 140, 50, 50), "Button3")) 
     { 
     // Third Button content here. 
     } 
    }  
} 

回答

0

我會嘗試實現的邏輯「點擊一個按鈕來激活下一個」從統一UI separatly。只要保持布爾這些都是積極的,哪些不是(或者設置一個int變量,如果它只是一個在每個時間點),如:

bool b1Active = true; 
bool b2Active = false; 
bool b3Active = false; 

if(b1Active && GUI.Button()) 
{ 
    b1Active = false; 
    b2Active = true; 

    // do stuff here  
} 

if(b2Active && GUI.Button()) 
{ 
    b2Active = false; 
    b3Active = true; 

    // do other stuff here 
} 

... 

我不知道這是否是實現這一最有效的方法但我認爲這個方向的方法能成功(如果我沒有誤解你的問題)

PS:如果你不想顯示的按鈕,如果他們不主動,你可以試試這個:

if(b1Active) 
{ 
    if(GUI.Button()) 
    { 
     b1Active = false; 
     b2Active = true; 

     // do stuff here 
    } 
} 
0
var toggle : boolean; 
var toggle2 : boolean; 
var toggle3 : boolean; 

function OnGUI() 
{ 
    toggle = GUI.Toggle(Rect(335, 80, 50, 50), toggle, "Button1", "button"); 

    if (toggle) 
    { 
     toggle2 = GUI.Button(Rect(335, 140, 50, 50), "Button2", "button"); 
    } 

    if(toggle2) 
    { 
      toggle3 = GUI.Button(Rect(335, 140, 50, 50), "Button3", "button"); 
    } 

     if (toggle3) 
     { 
      // Third Button content here. 
     }  

}