Unity Scripts

smallarrows.GIF

Disable Teleport Hint on Controllers
Select Teleporting in the Hierarchy.
     Scroll down to New script
          Type the name:  CancelTeleportHintScript
          Double click the new C# script in your Assets folder

Replace entire script with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR.InteractionSystem;

public class CancelTeleportHintScript : MonoBehaviour
{
    // Update is called once per frame
    void Start()
    {
        Teleport.instance.CancelTeleportHint();
    }
}



Script to hide the mouse cursor & add an Escape button
Select the Main Camera or an object
Select the Add Component button in the Inspector
     Scroll down to New script
          Type a name: hide_cursor_escape
          Double click the new C# script in your Assets folder

Replace entire script with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class hide_cursor_escape : MonoBehaviour
{
    // Use this for initialization
    void Start()
    {
        Cursor.visible = false;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
}





Script to rotate an object around the Y axis
Select an object in the Hierarchy
Select the Add Component button
     Scroll down to New script
          Type a name: rotate_object
          Double click the C# script in your Assets folder

Replace entire script with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rotate_object : MonoBehaviour {
 // Use this for initialization
 void Start () {
 }
 // Update is called once per frame
 void Update () {
        //this.transform.Rotate(x,y,z)
        this.transform.Rotate(0, Time.deltaTime*40, 0);
    }
}




Script to stretch a Ball along the X and Z axis in inverse relation to Y axis animation
This includes some work arounds since scaling is a bit limited in Unity.
Because you can not really separate x,y,z very easily, especially if animated.
Make a sphere with an extra node or parent in Maya.
Animate the sphere compressing the Y axis when it hits the ground using the parent level.
Add this script named squish to the child in Unity.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class squish : MonoBehaviour
{
    float baseScale, b, currentScale, c;
    void Start()
    {
        Vector3 baseScale = transform.localScale;
        b = baseScale.x; //x,y,z the same
    }
    void Update()
    {
        Vector3 currentScale = transform.parent.localScale;
        c = currentScale.y;
        transform.localScale = new Vector3(b/c, b, b/c);
    }
}





Start an Animation with a mouse click
Select the animated object in the Hierarchy
Select the Add Component button
     Scroll down to New script
          Type a name: mouse_start_anim
          Double click the C# script in your Assets folder

Replace entire script with this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class mouse_start_anim : MonoBehaviour {
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
            GetComponent<Animation>().Play();
    }
}



Script to help the SteamVR simulator work
This helps throwing objects and starting animation when you do not have a headset.
Written by Alex Rickett
Download this file   It is in your Downloads folder.
     PC right mouse over the file, select Extract All...
Place the file in your Assets folder
Drag and drop this script onto the Player->NoSteamVRFallbackObjects->FallbackHand in your Hierarchy  (SteamVR Player)