problem with singleton script

Hi!
I have instance attached to gameobject in main menu scene. When i change between scenes and return back to main menu scene 2 instances of class are active. How can i change my code to make only one istance of class available at time?
Thanks for helping!

public class soundManager : MonoBehaviour
{
   
   public static soundManager instance;

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != null )
        {
            Destroy(this);

        }
        DontDestroyOnLoad(this);

       
      
    }


  
    }




}

On line 15 instead of Destroy(this);you probably want:Destroy(this.gameObject);

1 Like

Thanks! Solved