Example #1
0
    public static Code_SoundSettings instance;               // Static variable so it is accessible from anywhere.
    #endregion

    private void Awake()
    {
        DontDestroyOnLoad(this.gameObject);       // Don't destroy this gameobject.
        curScene = SceneManager.GetActiveScene(); // Set the curScenes value by checking the sceneindex.
        if (instance == null)                     // Check if the instance variable is null.
        {
            instance = this;                      // Set the instance variable to this script Code_SoundSettings.
            DontDestroyOnLoad(gameObject);        // Don't destroy this gameobject. TODO: Check if this really needs to happen for the second time.
        }
        else if (instance != this)                // If the instance variable is not the same as itself.
        {
            GetValuesFromInstance();              // Call the GetValuesFromInstance Methode.
            Destroy(instance.gameObject);         // Destroy the instance once all values were transfered.
            instance = this;                      // Set this gameobject as the new instance value.
        }
    }
Example #2
0
    private void Awake()
    {
        DontDestroyOnLoad(this.gameObject);
        curScene = SceneManager.GetActiveScene();
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else if (instance != this)
        {
            // TODO get the values in the existing instance
            GetValuesFromInstance();

            // TODO DEstroy the instance once all values were transfered
            Destroy(instance.gameObject);

            // Set this gameobject as the new instance value
            instance = this;
        }
    }