DrawGUI and Door

I try make door open when Player have get keys. Else Gui text tell find this keys. Something in my script is wrong couse GUI text wont show up. I attact Script and every var what i put in code. Can someone tell where is problem?

#pragma strict
var auki : Animation;
var avain : GameObject;
private var drawGUI1 = false;
private var drawGUI2 = false;


function Start () {


}

function Update () {
if (drawGUI2 == true && Input.GetKeyDown(KeyCode.E))
{
animation.Play("auki");
}

}

function OnTriggerEnter (theCollider : Collider)
{
		if (theCollider.tag == "Player" && avain == true)
		{
		drawGUI1 = true;
		}
		if (theCollider.tag == "Player" && avain == false)
		{
		drawGUI2 = true;
}
}

function OnGUI ()
{
	if (drawGUI1 == true)
	{
	GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Find Key");
	}

	if (drawGUI2 == true)
	{
	GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E");
	}
}

I try couple differend ways to do this, but GUI text still wont show up.

1 Answer

1

I solved that problem, I make new function and now its look like this.

#pragma strict
var avain : GameObject;
var drawGUI1 = false;
var drawGUI2 = false;
private var doorIsClosed = true;
var theDoor : Transform;
var needkey = true;

function Start () {


}

function Update () {
if (drawGUI2 == true && Input.GetKeyDown(KeyCode.E))
{
	changeDoorState ();
	Destroy (gameObject);
}

}

function OnTriggerEnter (theCollider : Collider)
{
		if (theCollider.tag == ("Player") && needkey == true)
		{
		drawGUI1 = true;
		}
		if (theCollider.tag == ("Player") && needkey == false)
		{
		drawGUI2 = true;
}
}

function OnTriggerExit (theCollider : Collider)
{
		if (theCollider.tag == ("Player") && needkey == true)
		{
		drawGUI1 = false;
		}
		if (theCollider.tag == ("Player") && needkey == false)
		{
		drawGUI2 = false;
}
}	

function OnGUI ()
{
	if (drawGUI1 == true)
	{
	GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Find Key");
	}

	if (drawGUI2 == true)
	{
	GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press E");
	}
}

function changeDoorState ()
{
	if (doorIsClosed == true)
	{
	theDoor.animation.CrossFade("auki");
	doorIsClosed = false;
}
}

function getkey ()
{
 if (avain == true)
 {
 needkey = true;
 }
 if (avain == false)
 {
 needkey = false;
}
}

Now problem is the var needkey wont turn false… There is maybe better way to do this?