#On screen GUI buttons reference: http://docs.unity3d.com/Documentation/Components/gui-Basics.html
/* Button Content examples */
// JavaScript
var icon : Texture2D;
function OnGUI () {
if (GUI.Button (Rect (10,10, 100, 50), icon)) {
print ("you clicked the icon");
}
if (GUI.Button (Rect (10,70, 100, 20), "This is text")) {
print ("you clicked the text button");
}
}
#Hide and unhide reference: http://answers.unity3d.com/questions/299138/how-to-hide-and-unhide-object.html
function OnGUI () {
if(GUI.Button(Rect(0,0,200,100), "Reset"))
{
var wall = GameObject.Find("wallJumpTall");
if(!wall.renderer.enabled){
wall.renderer.enabled = true;
}
else {
wall.renderer.enabled = false;
}
}
}
The following hide/unhide recursively, notice that “floaty” need to be defined outside, and must be initialized in start()
function OnGUI () {
if(GUI.Button(Rect(0,0,200,100), "Reset"))
{
if(!floaty.activeSelf){
floaty.SetActiveRecursively(true);
}
else {
floaty.SetActiveRecursively(false);
}
}
}
#Axis
if (Input.GetAxis("Vertical") > 0) {
// checking for up arrow key
rigidbody.AddForce(10,0,0);
}
#Numbers
Random.Range(0, 3); // random number 0,1,2
#Smooth objects transitions using Lerp
reference: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html
//static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3
transform.position = Vector3.Lerp(transform.position, newPosition, 10 * Time.deltaTime);
Must be put in Update() in order to work. Might need to disble after transition done to reduce performance load. Use static function Distance (a : Vector3, b : Vector3) : float
to determine if is close enough to target position.