protected virtual void Awake() { if (_instance != null) { Debug.LogError("MonoSingleton [" + _instance.ToString() + "] allready exist"); Destroy(this); } _instance = GetComponent <T>(); if (dontDestroyOnLoad) { DontDestroyByLoad.EnableDontDestroyOnLoad(gameObject); } gameObject.SetActive(!hideAtLaunch); }
protected virtual void OnDestroy() { _instance = default; DontDestroyByLoad.OnDestroyObj(gameObject); }