Unity Scripts

smallarrows.GIF

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)



Remove the Dismembered Hand
In the Assets folder, Assets->SteamVR->InteractionSystem->Prefabs there are some hand prefabs.
Select LeftRenderModel Slim (default hand)
Uncheck
DisplayHand by Default toggle in the Inspector.
Do this for the Right hand too.



Script to hide the mouse cursor & add an Escape button
Select the Main Camera or an object
Select the Add Component button
     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();
        }
    }
}




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 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: rorate_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);
    }
}