32 lines
707 B
C#
32 lines
707 B
C#
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<DontDestroy>().Length; i++)
|
|
{
|
|
if (Object.FindObjectsOfType<DontDestroy>()[i] != this)
|
|
{
|
|
if (Object.FindObjectsOfType<DontDestroy>()[i].objectId == objectId)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
// DontDestroyOnLoad(gameObject);
|
|
|
|
}
|
|
}
|
|
}
|