using UnityEngine; public class MonoBehaviourSingletonPersistent : MonoBehaviour where T : Component { public static T Instance { get; private set; } public virtual void Awake () { if (Instance == null) { Instance = this as T; Instance.name = typeof(T).Name; DontDestroyOnLoad (gameObject); } else { Destroy (gameObject); } } }