Search Unity

toggle between 2d and Google Cardboard

Discussion in 'AR/VR (XR) Discussion' started by lz7cjc, May 21, 2020.

  1. lz7cjc

    lz7cjc

    Joined:
    Sep 10, 2019
    Posts:
    540
    Hi
    With the new Google Cardboard for Unity release I am updating my project.
    This is my current code
    Code (CSharp):
    1. public class VRToggle : MonoBehaviour
    2. {
    3.  
    4.     public void Start()
    5.  
    6.     {
    7.         StartCoroutine(SwitchToVR());
    8.         //  StartCoroutine(ActivatorVR("Cardboard"));
    9.  
    10.     }
    11.  
    12.     IEnumerator SwitchToVR()
    13.     {
    14.         // Device names are lowercase, as returned by `XRSettings.supportedDevices`.
    15.         string desiredDevice = "cardboard"; // Or "cardboard".
    16.  
    17.         if (System.String.Compare(XRSettings.loadedDeviceName, desiredDevice, true) != 0)
    18.         {
    19.             XRSettings.LoadDeviceByName(desiredDevice);
    20.  
    21.             // Must wait one frame after calling `XRSettings.LoadDeviceByName()`.
    22.             yield return null;
    23.         }
    24.  
    25.         // Now it's ok to enable VR mode.
    26.         XRSettings.enabled = true;
    27.  
    28.     }
    29. }
    30.  
    How do i update this for the new plugin based system?
    thanks