if the GUI is up when the player dies it stays up after respawn even though the player is out of the OnTriggerEnter for the GUI
#pragma strict
var theDoor : Transform;
private var doorIsClosed = true;
private var drawGUI = false;
function Update ()
{
if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
{
changeDoorState();
}
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
drawGUI = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
drawGUI = false;
}
}
function OnGUI ()
{
if (drawGUI == true)
{
GUI.Box (Rect (Screen.width*0.5-51, 400, 102, 22),"Press F to open");
}
}
function changeDoorState ()
{
if (doorIsClosed == true)
{
theDoor.animation.CrossFade("Door Open");
//theDoor.audio.PlayOneShot();
doorIsClosed = false;
yield WaitForSeconds(3);
theDoor.animation.CrossFade("Door Close");
//theDoor.audio.PlayOneShot();
doorIsClosed = true;
}
}