using UnityEngine; namespace GadGame.Singleton { /// /// This is basic singleton. This will destroy any new /// versions created, leaving the original instance intact /// /// Type of object you want to use singleton public abstract class Singleton : MonoBehaviour where T : Component { private static T _instance; public static T Instance { get { if (_instance == null) { _instance = FindObjectOfType(); if (_instance == null) { GameObject obj = new(typeof(T).Name); _instance = obj.AddComponent(); } } return _instance; } } protected virtual void Awake() { if (_instance != null && _instance != this) { Destroy(gameObject); return; } _instance = this as T; } } }