An on death pop up GUI

I am using this script on a character to have an enemy apply damage to the character.

var maximumhitPoints = 100;

var hitPoints= 100;

function ApplyDamage (damage:float) { if (hitPoints < 0) return;

//apply damage

hitPoints --;

if (hitPoints <= 0)

Die(); }

function Die() { if (hitPoints <=0)

//insert GUI here

}

but I'm having trouble understanding how to do GUI. All I want is for a window to pop up when you die that says you died and you can click an ok button. is this:

`static function Window (id : int, clientRect : Rect, func : WindowFunction, content : GUIContent) : Rect`

what I need to use? Thanks!

If you want to write a GUI in code it should be done in the function OnGUI(), you can't write GUI code inside one of your own functions. In your case you could use a boolean to check if a player is dead or not, like so:

var isDead = false;

function OnGUI()
{
    if (isDead)
    {
        GUI.Box(Rect(left, top, width, height), "You're dead");
        if(GUI.Button(Rect(left, top, width, height), "Click here"))
        {
            isDead = false;
        }
    }
}

function die()
{
    if(hitpoints <= 0)
        isDead=true;
}

function OnGUI() { print(""+boxselecting);

if(boxselecting){

    var width : int = leftupbox.x - rightdownbox.x;

    var height : int = (Screen.height - leftupbox.y) - (Screen.height - rightdownbox.y);

    var rect : Rect = Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, 

height);

    //GUI.Box(rect, "Its ALIVE");

    GUI.Box(Rect(rightdownbox.x, Screen.height - rightdownbox.y, width, height), "Its ALIVE");

    //GUI.DrawTexture(rect, selectionTexture, ScaleMode.StretchToFill, true, 10.0f);

    print("GUI");

}

} this is my code for drwng a box and unity still gives me the GUI can only be called in OnGUI error whats wrong with my code?