Advertisement
daserge

GVR Unity SwitchToTracked2D

Jul 26th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.XR;
  5.  
  6. public class VRModeSwitcher : MonoBehaviour
  7. {
  8.     public Transform MainCameraTransform;
  9.     void OnEnable ()
  10.     {
  11.         StartCoroutine (SwitchToTracked2D ());
  12.     }
  13.  
  14.     // 2D but also with head tracking enabled:
  15.     IEnumerator SwitchToTracked2D ()
  16.     {
  17.         XRSettings.enabled = false;
  18.         XRSettings.LoadDeviceByName ("cardboard");
  19.         yield return null;
  20.     }
  21.  
  22.     void Update ()
  23.     {
  24.         MainCameraTransform.localRotation = GvrVRHelpers.GetHeadRotation ();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement