unity-game-enginevirtual-realityoculusgo

How to switch scenes using the OVR Utilities?


I'm trying to switch scenes when an object in a VR environment is pressed. Should be a simple line of code but when I try to execute it the game crashes. The game is build to the Oculus Go.

I know I've added the scenes to the build to that shouldn't be the problem. I also got the index of '1' right in the build settings.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SphereScript : MonoBehaviour
{
    public void LoadScene()
    {
        SceneManager.LoadScene("1");
    }
}
private void ProcessTouchpadDown()
    {
        if (!m_CurrentObject)
            return;

        Interactable interactable = m_CurrentObject.GetComponent<Interactable>();
        CubeScript.onVRTriggerDown();
        SphereScript.LoadScene();

    }
}

Solution

  • There seems to be a small mistake in SceneManager.LoadScene("1");. If you want to load a scene by its built number and not by its name, you'll have to put in an integer and not a string. So unless your scene is named "1", this won't do the trick. Try SceneManager.LoadScene(1); instead.