Activating buttons

From Unify Community Wiki
Jump to: navigation, search

Author: Jediaction

Description

I made a simple script that you can use for button activations or anything similar to that. It detects when you get a specific distance to an object then makes a text come up telling you to activate by pressing a key. While you are within the specific distance key activation is enabled, and when you back away, it disables.

var target : Transform;
 
function OnGUI () {
 
if ( Vector3.Distance(target.position, transform.position ) > 1) 
{
	GUI.Label (Rect (40, 70, 200, 100), "");
	}
	else
	{
	GUI.Label (Rect (40, 70, 200, 100), "TYPE WHATEVER YOU WANT HERE");
	if(Input.GetKeyDown("e"))
		{
			Application.LoadLevel(1);
		}
}
 
 
if ( Vector3.Distance(target.position, transform.position ) < 1)
{
}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox