Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable VR from code

How can I set the display to stereoscopic programmatically in Unity for an app deployed to an Android device?

I want a UI menu where the user can toggle between "VR mode" and normal mode. I do not want VR mode by default as it should be an option at run-time. I know there is a setting for "Virtual Reality Supported" in the build settings, but again, I do not want this enabled by default.

like image 693
Sofia Clover Avatar asked Apr 18 '16 19:04

Sofia Clover


People also ask

How do I enable VR in unity?

Enabling Unity VR support To enable VR for your game builds and the editor, open the Player Settings (menu: Edit > Project Settings > Player). Select Other Settings and check the Virtual Reality Supported checkbox.


1 Answers

For newer builds of Unity (e.g. 2019.4.0f1) you can use the XR Plugin Management package.

To enable call:

XRGeneralSettings.Instance.Manager.InitializeLoader();

To disable call:

XRGeneralSettings.Instance.Manager.DeinitializeLoader();
like image 200
rusty Avatar answered Sep 29 '22 11:09

rusty