Display Texture after clicking on GUI Button

OK I’m not sure if this is the right place to ask this or should be asked at UnityGUI part of the forum but here goes.

Situation: I’m making a simple OnTriggerEnter, show GUI menu. i.e. if a character is within the collider space, a menu will pop-up and the player can select which part of the menu by pressing on the assigned hotkeys.

Problem: Pressing on the assigned hotkeys does not work. Nothing shows up.

Here’s my script:

private var showCounterMenu : boolean = false;
var Form1 : Texture;
var Form2 : Texture;

function OnTriggerEnter()
{
	showCounterMenu = true;
	GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;
}

function OnTriggerExit()
{
	showCounterMenu = false;
	GetComponent("MouseLook").enabled = true;
}

function OnGUI()
{
	if(showCounterMenu == true)
	{
	GUILayout.BeginArea(Rect(50,50,300,300), "Counter Menu");
	GUILayout.Box("Please select a form.");
		if(GUILayout.Button("Form 1 (Press F1)") || Input.GetKeyDown(KeyCode.F1))
		{
			GUILayout.Box(Form1);
		}
		if(GUILayout.Button("Form 2 (Press F2)") || Input.GetKeyDown(KeyCode.F2))
		{
			GUILayout.Box(Form2);
		}
	
	GUILayout.EndArea();
	}
}

Buttons will show, but they don’t work.

The trouble with that script is that the forms will only show for a single frame, so I guess it’s pretty much impossible to see them.

What you should do is make the button and hotkey enable a boolean flag, which you then check at the end of the function, and if it is true, then you draw the box.

You need to remember that OnGUI will draw and destroy each GUI element every frame, so if you want to display a box, you need to make sure the call to draw it is done every frame.