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;
}