Exemple #1
0
 private void OnDestroy()
 {
     Debug.Log($"Destroying singleton component at {gameObject.name}.");
     if (_instance == this)
     {
         _instance = null;
     }
 }
Exemple #2
0
 private void Awake()
 {
     if (_instance == null)
     {
         _instance = this;
     }
     else if (_instance != this)
     {
         // If there are several scripts in the scene, we need to make sure only one instance remains.
         Debug.LogWarning($"There is an existing singleton instance.");
         Destroy(this);
     }
 }