using System.Collections; using System.Collections.Generic; using UnityEngine; public class MonoSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance { get { if (_instance==null) { _instance = FindObjectOfType(); if (_instance == null) { _instance = new GameObject().AddComponent(); } } return _instance; } } protected virtual void Awake() { _instance = this as T; DontDestroyOnLoad(this.gameObject); } }