Help with calling and naming functions!

hey :)

iv been having trouble with this..im probably going over the top and/or over thinking it. but this is basically what im trying to do:

on my "Death.js"

function CreateDeathGUI()
{
    GUI.Box(Rect(Screen.width/2, Screen.height/2, 150,75), "You died");
};

function Die()
{
    CreateDeathGUI();
    transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos;
};

for the button that kills the player:

// Kill Player shit
    if (GUI.Button(Rect(10,25,130,30), "Die")){
        GameObject.Find('Player').GetComponent('Death').Die();
    }

now..it sets the players location back to spawn and everything....BUT it doesnt show the Deathgui

can help D:?

You have to call your GUI functions from the OnGUI() function, or show your GUI components in the OnGUI() function

You could probably make some minor changes to your code to show the gui on death.

// Added.
var showGui = false;

// Added.
function OnGUI()
{
    if (showGui)
    {
        CreateDeathGUI();
    }
}

// Same as before.
function CreateDeathGUI()
{
    GUI.Box(Rect(Screen.width/2, Screen.height/2, 150,75), "You died");
};

// Replaced call to CreateDeathGUI with this assignment instead
function Die()
{
    showGui = true;

    transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos;
};

Then you can have your calling code unaltered.

// Same as before.
if (GUI.Button(Rect(10,25,130,30), "Die"))
{
     GameObject.Find('Player').GetComponent('Death').Die();
}

If you would want to wait a bit before setting the position so the gui shows a bit before, then you can do something like this:

function Die()
{
    showGui = true;
    Invoke("Respawn", 3); // Wait 3 seconds to allow text to show a while
    Invoke("HideGui", 5); // And 2 seconds after respawn we should hide the gui
};

function Respawn()
{
    transform.position = GameObject.Find('Player').GetComponent('Spawn Pos').SpawnPos;
}

function HideGui()
{
    showGui = false;
}