GUI windows

Hi,
I have two windows, both drags good and when clicked highlights, but only one window buttons work. And the second one is the same size as the first one although i made it a lot bigger
can anyone help?

I tried something with focus, but only first window worked anyway. And theres no sence when you need to click window1 to activate window2.

var Player=false;
var Skills=false;
var windowRectPlayerStats : Rect = Rect (70, 100, 245, 215);  // <-- this works
var windowRectPlayerSkills : Rect = Rect (150, 100, 5000, 5000);  //<-- this should be big

function Update()
{
	if(Input.GetKey(KeyCode.P))
	{
		if(!Player)
		{
			Player=true;
		}
		else
		{
			Player=false;
		}
	}
	if(Input.GetKey(KeyCode.O))
	{
		if(!Skills)
		{
			Skills=true;
		}
		else
		{
			Skills=false;
		}
	}
}

function OnGUI()
{
	if(Player)
	{
		windowRectPlayerStats = GUI.Window (0, windowRectPlayerStats, WindowFunctionPlayer, "Player stats");
	}
	if(Skills)
	{
		windowRectPlayerSkills = GUI.Window (1, windowRectPlayerSkills, WindowFunctionSkills, "Skills");
	}
}

function WindowFunctionPlayer (windowID : int)
{
	GUI.DragWindow (Rect (0,0, 10000, 20));
	if (GUI.Button(Rect(10,30,100,30),"Increase number"))
	{
		number++;
	}
	GUI.Label (Rect (150, 150, 100, 30), ""+number);
}

function WindowFunctionSkills (windowID : int)
{
	var nothing=0;
	GUI.DragWindow (Rect (0,0, 10000, 20));
	if (GUI.Button(Rect(10,70,100,30), "BIG nothing"))
	{
	nothing++;
	}
	GUI.Label (Rect (150, 30, 100, 30), ""+nothing);
}

and also when i click “P” or “O” windows sometimes flashes and switches off. I need to click button few times while window turns on. Same with turning windows off.

You use Input.GetKey() in your Update() function. This is called every frame, so long as you press the key.
So your windows switches around 30 times per second, because each frame the Update() is called and switches your states.
The OnGUI() also called every frame (or more often) and react to this states of ´Player´ and ´Skills´.

To avoid a “repeating” button, you can use Input.GetKeyDown.
This will called only once if you press the key.

Thanks, now its a lot easier to open and close these windows.

In order to fix the flickering, use Input.GetKeyDown (or Up) because GetKey will be called as long as you hold down the key. In this case, it toggles the windows (or let’s say it’s representive booleans) on and off every frame!

When i run the code, both have their own correct size. In this case i cannot tell you what’s happening when you run it.

Additionally, instead of

if(!Skills)
        {
            Skills=true;
        }
        else
        {
            Skills=false;
        }

you can simplify it to

Skills = !Skills // this will have the same effect as your current if else structure, it toggles the boolean

The second button does actually work, but you won’t see the counter go up as you re-define the counter everytime the OnGUI is called. Put the declarations on top where the others are. Last but not least, which you might have forget to copy, there is no definition for number in the code you posted.

Thanks it works now!
And I don’t know what happened, but before I pasted this var nothing=0; in top my second window became the right size althought I haven’t done anything…

My both windows work good but I can’t change their size. (First’s windows too).
I created Player window on 3.1… and today upgraded to 4.3.4 and created Skills window. I could change Player window’s size easly when I first created it maybe there’s something with 4.3.4?

When I comment everything related to these two windows lounch game, then uncomment and lounch again window size changes, but to change it again i need to comment everything again…