Trigger problem in my 2D game!

Hello everyone!
I’ve made this script but my Gui doesn’t show up in my 2D game. Any advices please? :smiley:

#pragma strict

var theDoor : Transform;
private var drawGUI = false;
private var WizardShut = true;

function Update () 
{
	if (drawGUI == true && Input.GetKeyDown(KeyCode.T))
	{
		MakeWizardTalk();
	}
}

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, 200, 102, 22), "Press T to talk with Me!");
	}
}

function MakeWizardTalk ()
{
	if (WizardShut == true)
	{
		GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Hy there, I will help you in this journey!");
		WizardShut = false;
		yield WaitForSeconds(5);
		
		WizardShut = true;
	}
}

Yeah your drawGui will never be true there. Try changing it to true at the top and see if that works.

You also need to call MakeWizardTalk in your OnGUI code otherwise it wont draw anything when you call it from Update!

I made it like u say and the first GUI appears but notting happens when I press “T” and the GUI doesn’t desapears when I go far away from my NPC. So what should I do? :slight_smile:

#pragma strict

var theDoor : Transform;
private var drawGUI = true;
private var WizardShut = true;

function Update () 
{
	if (drawGUI == true && Input.GetKeyDown(KeyCode.T))
	{
		MakeWizardTalk();
	}
}

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, 200, 102, 22), "Press T to talk with Me!");
	}
	MakeWizardTalk();
}

function MakeWizardTalk ()
{
	if (WizardShut == true)
	{
		GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Hy there, I will help you in this journey!");
		WizardShut = false;
		yield WaitForSeconds(5);
		
		WizardShut = true;
	}
}