2013-11-22 9 views
0

У меня проблема с кнопкой gui внутри перетаскиваемого окна gui. В моей сцене у меня есть куб, и когда я нажимаю на него, он открывает окно. внутри окна есть кнопка для обновления куба. Проблема в том, что при открытии окна код кнопки обновления воспроизводится автоматически, как если бы он находился внутри функции обновления.Unity3D gui кнопка внутри gui окно ошибка

У меня есть тот же код внутри 2 других скриптов, где он отлично работает.

Кто-нибудь знает, что может быть неправильным?

У меня действительно не знаю, где я мог бы сделать что-то неправильно, так вот код я считаю, это уместно, если это не достаточно, пожалуйста, дайте мне знать, и я буду предоставлять больше информации :)

Вот код :

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

появляется этот вопрос будет off- тема , потому что это простая опечатка, и этот вопрос не поможет будущим посетителям – bummi

ответ

0

я обнаружил, что я имел точку с запятой в конце моего «если (GUI.Button ...», который моя игра не понравилась :)

Смежные вопросы