- Home /
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;
}
}
Do you call Do$$anonymous$$yWindow function from OnGUI()?
Answer by gogan1337 · Aug 26, 2014 at 05:05 PM
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 8-)
Answer by fueldown · Aug 26, 2014 at 06:11 PM
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. :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Gui Button Image 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
GUI.DrawTexture and assign it to a variable? 1 Answer
Help With Enemy Health bars 3 Answers