【发布时间】:2013-12-07 00:42:09
【问题描述】:
我在可拖动的 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));
}
【问题讨论】:
-
这个问题似乎是题外话,因为它是一个简单的错字,这个问题对未来的访问者没有帮助
标签: button user-interface window unity3d