GUI.Button not responding when drawn in a Rect.

My GUI Button is not responding!
I have placed a check in my script, and it fails the check.
Any ideas?

void DoMyWindow(int windowID) 
	{
		//---------------------------------------------------PAUSE---------------------------------------------------------------------
		if (windowID ==0)
		{

		}

		//----------------------------------------------------TOWER SELECTION---------------------------------------------------------------
		else if (windowID ==1)
		{
			//-----POWER SUPPLY-----
			if (GUI.Button(new Rect (0,0,Screen.width *0.12f, Screen.height *0.2f),powerSupply))
			{

				print ("power supply");
				powerSupplyOn++;
				if (powerSupplyOn == 1)
				{

				}

				else if (powerSupplyOn == 2)
				{
					print ("power supply spawn ready");
					gameObject.GetComponent <Tower_Placement>().powerSupply = true;
					powerSupplyOn = 0;
					structuresOn = false;
					windowRect = windowRectDisabled;
				}
			}

Hello,

Try


if (GUI.Button(Rect (0,0,Screen.width *0.12f, Screen.height *0.2f),powerSupply))


Insted of your


if (GUI.Button(new Rect (0,0,Screen.width *0.12f, Screen.height *0.2f),powerSupply))

new Rect never works for me, maybe just Rect works for you. I’m a newbie trying to help out :sunglasses:

you can’t allocate GUI elements in the function outside OnGUI(). Every button should be created inside ongui call. That is why you can’t use the button. :slight_smile: