using System.Collections; using System.Collections.Generic; using UnityEngine; public class AutoMonoSingleton: MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance { get { if(_instance==null) { GameObject obj = new GameObject(); obj.name = typeof(T).ToString(); DontDestroyOnLoad(obj); _instance = obj.AddComponent(); } return _instance; } } }