using UnityEngine; public class DontDestroy : MonoBehaviour where T : DontDestroy { static public T Instance { get; private set; } void Awake() { if (Instance == null) { Instance = (T)this; DontDestroyOnLoad(gameObject); OnAwake(); } else { Destroy(gameObject); } } void Start() { if (Instance == (T)this) { OnStart(); } } virtual protected void OnAwake() { } virtual protected void OnStart() { } }