繁体   English   中英

gui窗口内的Unity3D gui按钮错误

[英]Unity3D gui button inside gui window error

我在可拖动的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));
}

我发现我的“ if(GUI.Button ...)”结尾有一个分号,我的游戏不喜欢它:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM