简体   繁体   English

在Unity中,当我第二次加载场景时,某些对象没有显示

[英]In Unity, when I load a scene a second time, some objects don't show up

I have two scenes: Menu and Game. 我有两个场景:菜单和游戏。 I'm using C#. 我正在使用C#。

When you die in the game, you get sent back to the menu with 当您在游戏中死亡时,您将被发送回菜单

SceneManager.LoadScene("Menu");

There's a script with a GUIButton in the menu that, when clicked, loads the game with 菜单中有一个带有GUIButton的脚本,单击该脚本即可加载游戏

SceneManager.LoadScene("Game");

What I want to happen is that when I click the button in the menu scene, it loads the game as if I just clicked the play button with the game scene open in the editor. 我想发生的是,当我单击菜单场景中的按钮时,它将加载游戏,就好像我只是在编辑器中打开游戏场景时单击播放按钮一样。

What instead happens is that it goes to the game scene, but some objects from the game scene appear to be missing. 相反,发生的事情是它进入了游戏场景,但是游戏场景中的某些对象似乎丢失了。 I'm not using DontDestroyOnLoad() anywhere. 我不在任何地方使用DontDestroyOnLoad()。

Some objects from the scene do appear, but others don't. 场景中的某些对象确实出现,而其他对象则没有。 The weirdest thing is that there are some data fields on a script on the missing object that are referred to by some other scripts, and those give values that make sense. 最奇怪的是,缺少对象的脚本上有一些数据字段,其他一些脚本引用了这些数据字段,这些字段给出了有意义的值。

Does anyone have any idea what's going on, or what I can do to get the desired result? 有谁知道发生了什么事,或者我能做些什么以获得期望的结果?

原来的问题是,如果不是第一次创建对象,那我将销毁一个对象,而我却没有意识到。

are those static objects or dynamic? 是静态对象还是动态对象? try to instantiate them in function which gets called on scene loaded. 尝试在加载场景的函数中实例化它们。

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

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