Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created March 22, 2021 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unitycoder/3a2e1080134fb7cc6ac48dc31afbe9d9 to your computer and use it in GitHub Desktop.
Save unitycoder/3a2e1080134fb7cc6ac48dc31afbe9d9 to your computer and use it in GitHub Desktop.
toggle between 2d and Google Cardboard (2020 Unity XR)
https://forum.unity.com/threads/toggle-between-2d-and-google-cardboard.902378/#post-6959573
Coroutine StartVR()
{
return StartCoroutine(startVRRoutine());
IEnumerator startVRRoutine()
{
// Add error handlers for both Instance and Manager
var xrManager = XRGeneralSettings.Instance.Manager;
if (!xrManager.isInitializationComplete)
yield return xrManager.InitializeLoader();
if (xrManager.activeLoader != null)
xrManager.StartSubsystems();
// Add else with error handling
}
}
void StopXR()
{
var xrManager = XRGeneralSettings.Instance.Manager;
if (!xrManager.isInitializationComplete)
return; // Safety check
xrManager.StopSubsystems();
xrManager.DeinitializeLoader();
}
// And perhaps this too, if you are experiencig a distorted or stretched screen after exiting VR:
camera.ResetAspect();
camera.fieldOfView = defaultFov;
camera.ResetProjectionMatrix();
camera.ResetWorldToCameraMatrix();
@unitycoder
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment