using UnityEngine; namespace UltraCombos { public abstract class Singleton : MonoBehaviour where T : Component { #region Fields private static T instance; [SerializeField] private bool persistance = true; #endregion #region Properties public static T Instance { get { if (instance == null) { instance = FindFirstObjectByType(); if (instance == null) { var go = new GameObject(); go.name = typeof(T).Name; instance = go.AddComponent(); } } return instance; } } #endregion #region Methods protected virtual void Awake() { if (instance == null) { instance = this as T; if (persistance) { DontDestroyOnLoad(gameObject); } } else { Destroy(gameObject); } } #endregion } }