Display GUI when function is called

How can you get a GUI to appear when a function is called. none of the examples in the scripting referance show how to do this.
This is what I have so far.

var windowRect : Rect = Rect (20, 20, 120, 50);



function OnTriggerEnter (player) 
	{
		Debug.Log("NPC contact");
		NPC_GUI();
	}

function Start () 
{
	player = GameObject.Find("player");
}


function NPC_GUI()
{
	// Create GUI
	GUI.Box (Rect (10,10,200,90), "Test");
	
}

The game runs fine but when NPC_GUI is called I get the error.

ArgumentException: You can only call GUI functions from inside OnGUI.
UnityEngine.GUIUtility.CheckOnGUI ()
UnityEngine.GUI.Box (Rect position, UnityEngine.GUIContent content, UnityEngine.GUIStyle style)
UnityEngine.GUI.Box (Rect position, System.String text)
dialog.NPC_GUI () (at Assets/Standard Assets/Scripts/my scripts/dialog.js:20)
dialog.OnTriggerEnter (System.Object player) (at Assets/Standard Assets/Scripts/my scripts/dialog.js:8)

I think a workaround would be to add a script to a object when the gui is needed then take it away. is there a better way?

In OnGUI

If (somestate is_true)
 GUI.Box (Rect (10,10,200,90), "Test");

some other code sets somestate to false to turn off the GUI component.

I think you want something like this:

var windowRect : Rect = Rect (20, 20, 120, 50);
private var showGUI = false;
 
function OnTriggerEnter (player) 
{
	Debug.Log("NPC contact");
	showGUI = true;
}
 
function Start () 
{
    player = GameObject.Find("player");
}
 
function OnGUI()
{
    // Create GUI
    if (showGUI)
    	GUI.Box (Rect (10,10,200,90), "Test");
}