using System.Collections; using System.Collections.Generic; using UnityEngine; public class Singleton : MonoBehaviour where T : Singleton { public static T Instance { get { return _instance; } } private static T _instance; protected virtual void Awake() { if (_instance) { Destroy(_instance); } _instance = (T)this; } protected virtual void OnDestroy() { if (_instance == this) { _instance = null; } } }