using UnityEngine; public class Singleton : MonoBehaviour where T : Component { public static T Instance { get; protected set; } public virtual void Awake() { if (Instance == null) { Instance = this as T; } if (Instance != this) { Object.Destroy(base.gameObject); } } }