Ejemplo n.º 1
0
 // This method is called when the script is destroy
 protected void OnDestroy()
 {
     // If this is the currently active singleton, delete the static instance too
     if (singleton == this)
     {
         singleton = null;
     }
 }
Ejemplo n.º 2
0
 // This method is called when the script is loaded, but the component does not need to be enabled yet
 protected void Awake()
 {
     // Check if there is already a singleton instance
     if (singleton == null)
     {
         singleton = this;
         DontDestroyOnLoad(singleton);
         init();
     }
     else
     {
         Destroy(this);
     }
 }