Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button gui窗口内的Unity3D gui按钮错误_Button_User Interface_Window_Unity3d - Fatal编程技术网

Button gui窗口内的Unity3D gui按钮错误

Button gui窗口内的Unity3D gui按钮错误,button,user-interface,window,unity3d,Button,User Interface,Window,Unity3d,我在可拖动gui窗口中的gui按钮上遇到问题。在我的场景中,我有一个立方体,当我单击它时,它会打开一个窗口。在窗口内有一个升级立方体的按钮。问题是,当窗口打开时,升级按钮代码会自动播放,就好像它在更新函数中一样 我在另外两个脚本中有完全相同的代码,它可以完美地工作 有人知道可能出了什么问题吗 我真的不知道我在哪里做错了什么,所以我认为这里的代码是相关的,如果还不够,请让我知道,我会提供更多信息:) 代码如下: function Upgrade () { var price : float

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

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

这个问题似乎离题了,因为它是一个简单的打字错误,这个问题对未来的访问者没有帮助