繁体   English   中英

如何在没有错误的情况下加载我的场景 [场景尚未添加到构建设置或 AssetBundle 尚未加载]

[英]how can I load my scenes without the error [scene has not been added to the build settings or the AssetBundle has not been loaded]

我有一个无法加载的场景错误。

我有两个场景。 如果我的服务器请求的场景不同但未加载,我会更改当前场景。

无法加载场景“/Assets/Beach_Essentials/DemoScene”,因为它尚未添加到构建设置中或尚未加载 AssetBundle。 要将场景添加到构建设置,请使用菜单 File->Build Settings... UnityEngine.SceneManagement.SceneManager:LoadScene (string)

但我的场景在构建设置中。

请问有人遇到过这样的问题吗?

我从像这样定义的 json 中获取请求场景的名称:

    requested_scene = root["item"]["asset"]; 
    private void Update()
        {
            // Check if the name of the current Active Scene is your first Scene.
            if(requested_scene != "")
            {
                Debug.Log("Try to load scene "+requested_scene);
                Scene current_scene = SceneManager.GetActiveScene();
                if(current_scene.name != requested_scene)
                {
                    SceneManager.LoadScene(requested_scene);
                    Debug.Log("Scene loaded"+requested_scene);
                }
            }
    //rest of the code
    }

构建设置捕获

错误

您认为我必须在下图所示的常规环境或UI环境中制作场景:

项目设置

出现此问题是因为价值的requested_scene

你把完整路径/Assets/Beach_Essentials/DemoScene )在requested_scene变量。 只需将场景名称添加到变量中即可。

像这样:

requested_scene = "DemoScene";
SceneManager.LoadScene(requested_scene);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM