Ejemplo n.º 1
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this; // In first scene, make us the singleton.
         DontDestroyOnLoad(gameObject);
     }
     else if (instance != this)
     {
         Destroy(gameObject); // On reload, singleton already set, so destroy duplicate.
     }
 }
 void Awake()
 {
     // Set instance if doesn't exist
     if (!instance)
     {
         instance = this;
     }
     else   // prevent duplicate
     {
         Destroy(this.gameObject);
         return;
     }
     DontDestroyOnLoad(this.gameObject);
 }
    void Awake()
    {
        if (!instance)
        {
            instance = this;
        }
        else
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);
    }
    void Awake()
    {
        //Exception handling setting an instance if there is none
        if (!instance)
        {
            instance = this;
        }
        else
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);
    }
Ejemplo n.º 5
0
    // For sake of example, assume -1 indicates first scene
    //public int prevScene = -1;

    void Awake()
    {
        // If we don't have an instance set - set it now
        if (!instance)
        {
            instance = this;
        }
        // Otherwise, its a double, we dont need it - destroy
        else
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);
    }
Ejemplo n.º 6
0
    void Awake()
    {
        //If we don't have an instance set - set it now
        if (!instance)
        {
            instance = this;
        }
        //Otherwise, its a double, we dont need it - destroy
        else
        {
            Destroy(this.gameObject);
            return;
        }

        //Makes the object permanent so that we can always check to see what scene the user came from previously even though we changed the scene.
        DontDestroyOnLoad(this.gameObject);
    }