简体   繁体   English

重新加载游戏场景时,对象不会统一加载

[英]When I reload my game scene the objects do not reload in unity

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

public class SceneLoader : MonoBehaviour
{
    Scene scene;
    private void Awake()
    {
        scene = SceneManager.GetActiveScene();
    }

    public void LoadScene(string level)
    {
        if (level == "Game")
        {
            SceneManager.LoadScene("Game");

        }
        else
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene(level);
        }
    }
}

When it reloads the game scene the objects are stationary like when they were when the scene finished. 重新加载游戏场景时,对象静止不动,就像场景结束时一样。

What you do is supposed to work. 您所做的应该是可行的。

The only objects that are not reloaded are those that have a script containing DontDestroyOnLoad . 唯一不重新加载的对象是那些包含DontDestroyOnLoad脚本的脚本。 You should check if this is the case for your objects 您应该检查对象是否属于这种情况

By the way, your if-else blocks are useless, they do the same thing as if you wrote 顺便说一下,您的if-else块是无用的,它们的作用与您编写的相同

public void LoadScene(string level)
{
    SceneManager.LoadScene(level);
}

If the objects are showing in the Scene view but not in the hierarchy, you should check if the scene is collapsed. 如果对象显示在“场景”视图中而不是层次结构中,则应检查场景是否折叠。 If so, click the arrow to the left of the scene name. 如果是这样,请单击场景名称左侧的箭头。

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

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