What is the best method to trigger a display with options?

Hi I’m a newbie to JavaScript.

This is what I’d like to do.
When a box collider is triggered. I want a “display” to appear which contains text, and a button to open a URL and a button to exit the “display”. Once exited from the “display” I want to remain in my original location.

Any ideas how I can do this?
Thanks

Hey, This answer assumes you have a tag on the object you’re colliding with the box collider which i’ll use the tag “Player” for, but replace this with yours.

private var displayMessage : boolean;

function OnTriggerEnter(other : Collider)
{
	if(other.tag == "Player")
	{
		displayMessage = true;
	}
}

function OnGUI()
{
	if(displayMessage)
	{
		GUI.Box(Rect(200,100,Screen.width - 400, Screen.height - 200),"Box Text");
		if(GUI.Button(Rect(Screen.width/3 - 100,Screen.height - Screen.height/2.5,200,100),"QUIT Button"))
		{
			displayMessage = false;
		}
		if(GUI.Button(Rect(Screen.width/3*2 - 100,Screen.height - Screen.height/2.5,200,100),"URL Button"))
		{
			Application.OpenURL("URL HERE");
		}
	}
}

You should just be able to drop this code onto the object with the box collider and as long as the object has a rigid body attached to it (be sure to turn off use gravity so it doesn’t just fall through the floor) and that the isTrigger check box is checked on the box collider component attached to the object.

The reason I use the screen height and width to place the box and buttons is so that it looks the same at any resolution.

Naturally it doesn’t look the best in these positions, but by playing around with them you can make it look more like what you’re looking for.

I hope this helps. :slight_smile:

Hi froYo

Worked like a dream. I had a problem with the “tag” at first but once I researched that it worked fine.
Now to fill up the box text with some text :slight_smile:

BIG THANKS

[7993-boxtxt+pic.jpg|7993]

I just want to add another thank you very much for this script - it works perfectly and looks great!