[英]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.