- Home /
Buttons in window problem
I have this window with a set of buttons in it. These buttons get made by a loop pulling information from somewhere else. It works all fine until I go to try and click a button. When I hover of the button, it looks like it gets pushed, but it is not being pushed. Then pushing the button doesn't work as well. Any ideas why?
function gameWindow(id : int){
var a : int = gameList.gameCount;
var yLoc : int = -35;
for(var x = 0; x < a; x++){
yLoc += 45;
var gameID : int = game.id[x];
var turnNumber : int = game.turn[x];
var button = GUI.Button(Rect(10, yLoc, 780, 35), "Game ID: " + gameID + " " + "Turns Completed: " + turnNumber);
if(button){
Debug.Log("It worked! " + gameID);
}
}
GUI.BringWindowToBack(0);
GUI.UnfocusWindow();
}
function OnGUI () {
GUI.Window (0, Rect(Screen.width/2 - 400, Screen.height/2 - 300, 800, 600), gameWindow, "");
}
Answer by raoz · Mar 26, 2012 at 04:51 PM
It looks like it doesn't get pressed, because it must be pressed the moment it is drawn, or something in this manner. GUI.RepeatButton works, however, because it can be already clicked. But GUI.RepeatButtun gives you "It worked" like every time it gets drawn or so, so very often. There might be a better solution, but I cannot see one.
I was thinking that it was pressed as soon as it came up as well. There is a load time. Now that I can look at it, I will try just putting them in front of a GUI.box. See if I get the same issue. I really would like it in a window so I can show and hide the window as I need.
Answer by Bunny83 · Mar 26, 2012 at 05:23 PM
Remove those two lines:
GUI.BringWindowToBack(0);
GUI.UnfocusWindow();
You unfocus the window every frame. You can never use any GUI element in the window this way.
Except I added those htat way you cant focus on the window itself. $$anonymous$$aybe I should remove the BringWindowToBack?
Your answer
Follow this Question
Related Questions
How do I draw controls in a GUI Window - based on screen dimensions? 2 Answers
Dragging and Locking Buttons. 1 Answer
Add EditorUI elements when a button is pressed 0 Answers
GUI Button and Window 1 Answer
A few GUI related questions. 1 Answer