using UnityEngine; public class MonoSingleton : MonoBehaviour where T : MonoBehaviour { protected static T _instance = null; public static T Instance { get { if (_instance == null) { _instance = FindObjectOfType(typeof(T)) as T; if (_instance == null) { GameObject obj = new GameObject(nameof(T)); _instance = obj.AddComponent(); } DontDestroyOnLoad(_instance.gameObject); } return _instance; } } public static bool IsNull() { if (_instance == null) { _instance = FindObjectOfType(typeof(T)) as T; } return _instance == null; } public static void RemoveInstance() { if (_instance == null) return; _instance = null; } }