我认为你要找的是“保存”哪些对象被删除的方法:你只需要让你的类继承MonoBehaviour
并且调用DontDestroyOnLoad()
,这样你的包含脚本的对象将存在于场景之间。
public static class DestroyedObject : MonoBehaviour
{
public static DestroyedObject Instance;
private static List<GameObject> objs = new List<GameObject>();
private void Awake()
{
if (!Instance)
{
Instance = this;
}
else
{
DestroyImmediate(gameObject);
}
DontDestroyOnLoad(gameObject);
}
public static void Add(GameObject obj)
{
if(!objs.Contains(obj))
objs.Add(obj);
}
public static List<GameObject> GetDestroyedObjects()
{
return objs;
}
}
然后你只需访问使用DestroyedObject.Instance.Add()
或DestroyedObject.Instance.GetDestroyedObjects()
脚本(有些人不喜欢这种设计模式,但它已被证明使用Unity时是非常有效的)。
同样作为@Sergey问,为什么创建对象(在场景加载),以便之后删除它们:您可以执行反转操作(仅实例化所需的)。
希望这会有所帮助,
当场景开始时,你有一些被破坏的物体吗?为什么在场景开始之前创建和销毁某些东西? –
其隐藏的对象游戏,找到的对象被破坏然后你移动到另一个场景,你可以回到前一个场景多数民众赞成为什么有对象需要保持销毁 –
甚至没有注意到你严格复制粘贴代码@ m-rogalski在[你以前的问题]中提供了你(http://stackoverflow.com/questions/41547533/how-to-pass-the-destroyed-state-of-an-object-in-unity):也许你可以简单地问他,而不是开始一个新的问题...... – Kardux