GUI Label in if GUI.Button?

private var logintext : String = "Your Name";
function OnGUI ()
{
logintext = GUI.TextField (Rect (100, 40, 150, 20), logintext, 14);
if (GUI.Button (Rect ( 20, 10, 80, 30), "Connect"))
{
				if (logintext == "")
				{
					GUI.Label(Rect(200, 200, 100,50), "Text Here");      // Script reads this line, but this command isn't working.
					// If i use another command like Print. It is working but GUI isn't
				}
}
}

I don’t know why it’s not working. Every command is working except GUI.
Please help me :expressionless:

the label will only show when you click the button, you won’t event see it appear on screen.
use a boolean to show the label on screen and switch the boolean with the button

private var logintext : String = "Your Name";
private var mybool: boolean = false;

function OnGUI ()
{
	logintext = GUI.TextField (Rect (100, 40, 150, 20), logintext, 14);
	if (GUI.Button (Rect ( 20, 10, 80, 30), "Connect"))
	{
		if (logintext == "")
		{
			if(mybool == true)
				mybool = false;
			else
				mybool = true;
		}
if(mybool == true)
	GUI.Label(Rect(200, 200, 100,50), "Text Here");
}

not sure why you add ‘if (logintext == “”)’

Thanks it works.

if (logintext == “”) is just a sample. I just wanna make some controls when user clicked button or something.

i still don’t know why we can’t create a gui in " if gui.button(…) {gui} but no problem. Thank you.

because the time the button is clicked is 1 frame, so the label only shows during that frame. the time is to short to actualy see the label on the screen. once the frame has finished, the button isn’t in a click state anymore and the label is removed from the screen.

Thank you for helping. :slight_smile: