using UnityEngine; namespace SLSUtilities.General { public class Singleton : MonoBehaviour where T : MonoBehaviour { protected static T instance; public static T Instance => instance; protected virtual void Awake() { Initialize(false); } protected virtual void Initialize(bool dontDestroy) { if (dontDestroy) { if (instance == null) { instance = this as T; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } else { instance = this as T; } } } }