violetthesun
violetthesun

Reputation: 51

Unity select bool value from menu and load into google cardboard scene

I want the user to be able to select in the main menu if they want to start the game with VR Stereo enabled or if they want to load it in mono. Right now the GvrViewer script has a boolean checkmark in the GUI to enable/disable VR so I am trying to have the user essentially control that boolean from the main menu.

I'm not sure if I'm on the right path, but I have 2 buttons on the Main Menu that say "Enter in VR" and "Enter in Mono". Ideally, clicking on "Enter in VR" triggers a function that sets the boolean and loads the new scene with that boolean triggering the VR mode. However, I can't figure out how to pass the stored boolean into the new scene and have it override the settings already stored from the GUI inspector. I have tried "finding" the gameobject's value from my Menu script but I can't seem to have any success.

// buttons on main menu

public void LoadMono(int level) {
    MonoOrStereo.VRModeEnabled = false;
    Application.LoadLevel (level);
}

public void LoadStereo() {
    MonoOrStereo.VRModeEnabled = true;
    Application.LoadLevel (level);
}



// boolean provided by GvrViewer script for GUI inspector settings

bool VRModeEnabled {
    get {
      return vrModeEnabled;
    }
    set {
            if (value != vrModeEnabled && device != null) {
                device.SetVRModeEnabled(value);
      }
            vrModeEnabled = value;
    }
  }
  [SerializeField]
  public bool vrModeEnabled = false;

Upvotes: 0

Views: 247

Answers (1)

the.Legend
the.Legend

Reputation: 686

The correct approach would be to have Game manager object which is persistent across the game and has control over settings class object.

In case if you still need to get to Public boolean visible in inspector, use this approach:

SettingsObject = GameObject.FindGameObjectsWithTag("Settings");
SceneManager = SettingsObject.GetComponent<SomeSceneManagerClass>();
Scenemanager.vrModeEnabled = true; 

It's hard to tell exactly what needs to be done because I need to see the structure of your project, which classes are managing your project and how they are composed in Inspector

(please note that the code above just indicates the approach and may not work as you want it to. For it to be useful in your case the data I mentioned above is required)

Upvotes: 1

Related Questions