如何使用 OVR Utilities 切换场景?

How to switch scenes using the OVR Utilities?

我正在尝试在按下 VR 环境中的对象时切换场景。应该是一行简单的代码,但是当我尝试执行它时游戏崩溃了。该游戏是为 Oculus Go 构建的。

我知道我已经将场景添加到构建中,这应该不是问题。我还在构建设置中获得了索引“1”。

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();

    }
}

SceneManager.LoadScene("1");好像有点小错误。如果你想通过它的内置编号而不是它的名称来加载场景,你必须输入一个整数而不是一个字符串。所以除非你的场景被命名为“1”,否则这不会成功。请尝试 SceneManager.LoadScene(1);