2013-11-22 55 views
0

我在可拖動的gui窗口內出現gui按鈕的問題。在我的場景中,我有一個立方體,當我點擊它時,它會打開一個窗口。在窗口內部有一個用於升級多維數據集的按鈕。問題是,當窗口打開時,升級按鈕代碼會自動播放,就好像它已經在更新功能中一樣。gui窗口內的Unity3D gui按鈕錯誤

我有兩個完全相同的代碼完全相同的代碼。

有誰知道什麼可能是錯的?

我真的不知道在哪裏我可以做錯事,所以這是我認爲的代碼是相關的,如果這還不夠,請讓我知道,我會提供更多的信息:)

下面的代碼:

function Upgrade() 
{ 
    var price : float; 
    price = (level * 400) + 400; 

    if (budget > price) 
    { 
     level++; 
     budget -= price; 
     maxStorage += 10; 
     Debug.LogWarning("Upgraded to level " + level); 
    } 
    else 
    { 
     Debug.LogWarning("Upgrade failed. Not enough money."); 
    } 
} 

function OnGUI() 
{ 

    if (windowOpen == true) 
    { 
     windowRect = GUI.Window (windowId, windowRect, WindowFunction, "Statistics Industry"); 
    } 
    if (tooltip != "") 
    { 
     GUI.BeginGroup (new Rect (25, Screen.height - 125, 200, 100)); 
     GUI.Box (new Rect (0, 0, 200, 100), ""); 

      GUI.Label (Rect (15, 15, 170, 70), tooltip); 

     GUI.EndGroup(); 
    } 

} 
function WindowFunction (windowID : int) 
{ 
    GUI.Label (Rect (25, 25, 175, 30), "Location: " + cityName); 
    GUI.Label (Rect (25, 50, 175, 30), "Budget: " + budget); 
    GUI.Label (Rect (25, 75, 175, 30), "Storage: " + storage + "/" + maxStorage); 
    GUI.Label (Rect (25, 100, 175, 30), "Energy: " + Mathf.Round(energy)); 
    GUI.Label (Rect (25, 125, 175, 30), "Tax: " + taxPercent + "%"); 

    //goods price pr unit 
    GUI.Label (Rect (25, 150, 175, 30), "Price for goods."); 
    sellPrice = GUI.HorizontalSlider (Rect (25, 181, 100, 15), sellPrice, 0.0, 10.0); 
    GUI.Label (Rect (135, 175, 75, 30), "price: " + sellPrice.ToString("0.0")); 
    //Create help button 
    GUI.Button (new Rect (155, 150, 25, 25), GUIContent("?", "This is the price which the Industry will take for each piece of Material. \nSelling to Market.")); 
    //Display the tooltip 
    if (Event.current.type == EventType.Repaint) 
    { 
     tooltip = GUI.tooltip; 
    } 

    //energy price pr unit 
    GUI.Label (Rect (25, 200, 175, 30), "Price for energy."); 
    energyPrice = GUI.HorizontalSlider (Rect (25, 231, 100, 15), energyPrice, 0.0, 10.0); 
    GUI.Label (Rect (135, 225, 75, 30), "price: " + energyPrice.ToString("0.0")); 
    //Create help button 
    GUI.Button (new Rect (155, 200, 25, 25), GUIContent("?", "This is the price which the Industry will pay for each piece of Energy. \nBuying from Consumer.")); 
    //Display the tooltip 
    if (Event.current.type == EventType.Repaint) 
    { 
     tooltip = GUI.tooltip; 
    } 
    //Upgrade button 
    if (GUI.Button (new Rect (25, 250, 150, 25), "Upgrade " + "(" + level + ")")); 
    { 
     Upgrade(); 
    } 

    if (GUI.Button (new Rect (25, 280, 150, 25), "Close")) 
    { 
     renderer.material.mainTexture = mainTexture; 
     windowOpen = false; 
    } 
    GUI.DragWindow (Rect (0,0,10000,10000)); 
} 
+0

這個問題似乎會偏離話題 ,因爲它是一個簡單的錯字,這個問題對未來的訪問者沒有幫助 – bummi

回答

0

我發現我已經在我的最後一個分號「如果(GUI.Button ......」這遊戲我不喜歡:)