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