我现在有A场景和B场景,现在A场景的物体A1,DontDestroyOnLoad后切换到b场景在b场景中DestroyA1。
然后B场景切换回A场景 现在A场景有时会有两个A1物体
A1代码
public class KeepPlayers : MonoBehaviour
{
public static KeepPlayers instance;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this);
}
else
{
Destroy(this);
}
Debug.Log(instance == null);
}
}