using UnityEngine; public class SingletonAutoMono : MonoBehaviour where T : MonoBehaviour { private static T instance; public static T Instance { get { if (instance == null) { GameObject obj = new GameObject(typeof(T).ToString()); instance = obj.AddComponent(); DontDestroyOnLoad(obj); } return instance; } } }