- Home /
toggle VRSettings
Hello, I want to be able to toggle VR with a Samsung Gear App so that I can go back an forth between a normal App and VR Mode with the Galaxy
using UnityEngine;
using System.Collections;
namespace VRStandardAssets.Examples
using VRStandardAssets.Utils;
public class EnableVr : MonoBehaviour {
void OnMouseUp() {
ToggleVRMode();
}
public void ToggleVRMode() {
VRSettings.enabled = !VRSettings.enabled;
}
}
But I get this error (why I added the VRAssets to the build ; ):
Assets/_Scripts/EnableVr.cs(18,17): error CS0103: The name `VRSettings' does not exist in the current context.
I realize I will eventually have to use a raycast
Thanks
~be
Answer by Paul-Jan · Apr 03, 2016 at 05:29 PM
According to the API reference, VRSettings is part of the UnityEngine.VR
namespace, so that is the one you should be using.
Also, what is that namespace doing half-way your units? It's missing a semi-colon, so your current code-sample wouldn't compile anyway.
A compiling version of your script:
using UnityEngine;
using UnityEngine.VR;
public class EnableVr : MonoBehaviour
{
void OnMouseUp()
{
ToggleVRMode();
}
public void ToggleVRMode()
{
VRSettings.enabled = !VRSettings.enabled;
}
}
@Paul-Jan, Thank you ! I will try today and get back to you
Do you know why when toggleing VR$$anonymous$$ode the objects in my scene get invisible, except for a canvas in world space? I've tried to toggle VR $$anonymous$$ode like this and accessing the instance of Gvr Viewer, but always get the same under Unity 5.5.3, GVR SF$$anonymous$$ 1.30.
Your answer
![](https://koobas.hobune.stream/wayback/20220612074053im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
enable & disable VR on mobile 2 Answers
[Solved]cant disable/enable scripts 1 Answer
Turning script not enabling/disabling? 1 Answer
Disable And Enable Trigger 4 Answers
Have objects persist in one scene, and not across all scenes? (C#) 0 Answers