简体   繁体   English

游戏重新开始时销毁所有先前创建的对象

[英]Destroying all the previously created objects when the Game Start over

In my game I am using Destroy(gameObject) for some gameobjects to pass them on another level.在我的游戏中,我将Destroy(gameObject)用于某些游戏对象以将它们传递到另一个级别。 Now the problem is after my player dies there are objects left on the scene when I restart the game after the player dies, I only want the objects that i created when the game started.现在的问题是在我的玩家死后,当我在玩家死后重新启动游戏时,场景中会留下一些对象,我只想要游戏开始时创建的对象。 How can I accomplish this?我怎样才能做到这一点?

将玩家创建的游戏对象存储在一个列表中,然后在重新启动后对它们调用Destroy()

First of all if you need to destroy object that you marked with DontDestroyOnLoad you are doing something wrong.首先,如果您需要销毁用DontDestroyOnLoad标记的对象,那么您做错了。

Use it only on objects that you really want to keep across the scenes.仅将其用于您真正希望在整个场景中保留的对象。 If you need to make changes in these objects, just change parameters values and make other objects live only in scenes where they belong.如果您需要对这些对象进行更改,只需更改参数值并使其他对象仅存在于它们所属的场景中。

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

相关问题 C#/MonoGame - 当我卸载我的游戏关卡时销毁 memory 中的大型对象 - C#/MonoGame - Destroying large objects in memory when I unload my game level 在Unity中每隔一定数量的帧创建和销毁游戏对象 - Creating and destroying game objects each certain number of frames in Unity 摧毁所有孩子时团结定格 - Unity freezes when destroying all children 销毁游戏对象 - Destroying game object 将新对象添加到列表时,先前已添加的所有对象将被覆盖 - When adding a new object to the list all the objects already added previously are overwritten Unity 2D触摸代码会销毁所有对象? - Unity 2D touch code destroying all objects? 如何循环遍历层次结构中的所有游戏对象,包括两个场景中的禁用对象所有子对象? - How can I loop over all game objects in hierarchy including disabled objects all children too in both scenes? 为什么在重新加载游戏场景时开始新游戏时它还会记住一个标志状态为真? - Why when making start a new game when it's loading the game scene over again it also remember one flag state as true? 如何使用列表<gameobject>在实例化和销毁对象时窃取 GameObject[]?</gameobject> - How to use List<GameObject> insteal GameObject[] when instantiating and destroying objects? 统一销毁非法对象 - Destroying instatiated objects in unity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM