Skip to content

Instantly share code, notes, and snippets.

@JT5D
Forked from radiatoryang/VRUtility.cs
Created September 9, 2016 08:56
Show Gist options
  • Save JT5D/7ac70c1579a30db78e6c86152bb5eeff to your computer and use it in GitHub Desktop.
Save JT5D/7ac70c1579a30db78e6c86152bb5eeff to your computer and use it in GitHub Desktop.
a script I give to my Unity VR students that demonstrates a few useful "quality of VR" features for their games -- lowering visual quality for higher framerate, and HMD recentering
using UnityEngine;
using System.Collections;
using UnityEngine.VR; // you always need this to use special VR functions
public class VRUtility : MonoBehaviour {
// Use this for initialization
public void Start () {
// set render quality to 50%, sacrificing visual quality for higher FPS
// this is pretty important on laptops, where the framerate is often quite low
// 50% quality actually isn't that bad
VRSettings.renderScale = 0.50f;
}
// Update is called once per frame
void Update () {
if ( Input.GetKeyDown(KeyCode.R) ) {
InputTracking.Recenter(); // recenter "North" for VR, so that you don't have to twist around randomlys
}
// dynamically adjust VR visual quality in-game
if ( Input.GetKeyDown(KeyCode.RightBracket) ) { // increase visual quality
VRSettings.renderScale = Mathf.Clamp01( VRSettings.renderScale + 0.1f);
}
if ( Input.GetKeyDown(KeyCode.LeftBracket) ) { // decrease visual quality
VRSettings.renderScale = Mathf.Clamp01( VRSettings.renderScale - 0.1f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment