我在可拖动的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 :(得分:0)
我发现我的“if(GUI.Button ......”,我的游戏不喜欢的结尾处有一个分号)。