using System.Collections; using System.Collections.Generic; using UnityEngine; public class DontDestroy : MonoBehaviour { [HideInInspector] public string objectId; private void Awake() { objectId = name + transform.position.ToString(); } void Start() { for (int i = 0; i < Object.FindObjectsOfType().Length; i++) { if (Object.FindObjectsOfType()[i] != this) { if (Object.FindObjectsOfType()[i].objectId == objectId) { Destroy(gameObject); } } DontDestroyOnLoad(gameObject); } } }