我正在尝试在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);
。