Activating buttons

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m
m
Line 1: Line 1:
{{cleanup}}
+
Author: [[User:Jediaction|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.'''
+
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.
 
+
  
 +
<javascript>
 
var target : Transform;
 
var target : Transform;
  
Line 27: Line 28:
 
}
 
}
 
}
 
}
 +
</javascript>

Revision as of 17:09, 20 September 2011

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.

<javascript> 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) { } } </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox