Ejemplo n.º 1
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
Ejemplo n.º 2
0
    private void Awake()
    {
        DontDestroyOnLoad(this.gameObject);

        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this.gameObject);
            return;
        }
    }
Ejemplo n.º 3
0
 void Awake()
 {
     if (dontDupe)
     {
         //Check if instance already exists
         if (Dontdestroy == null)
         {
             //if not, set instance to this
             Dontdestroy = this;
         }
         //If instance already exists and it's not this:
         else if (Dontdestroy != this)
         {
             //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
             Destroy(gameObject);
         }
     }
 }