Stop background music on scene enter

Hi :slight_smile:
i have background music playing throughout the scenes,i cant figure it out how to stop bck music on game scene enter,this is my code. What is the best solution?

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class Music : MonoBehaviour
{

static Music instance = null;

     void Awake()
    {
        if (instance != null)
        {

            Destroy(gameObject);
        }
        else
        {
            instance = this;
            GameObject.DontDestroyOnLoad(gameObject);
        }

    }
public void ToggleSound()
{

    if (PlayerPrefs.GetInt("Muted", 0) == 0)
    {
        PlayerPrefs.SetInt("Muted", 1);

    }
    else
    {
        PlayerPrefs.SetInt("Muted", 0);
    }

}

}

You need to get a reference to your AudioSource, then set the mute property to true, to mute the audio. Assuming this script is attached to the same object that contains the AudioSource, then you could do something like thisโ€ฆ

In your declarations...

AudioSource myAudio;

void Start(){
  myAudio = GetComponent<AudioSource>();
}

then in your toggle sound routine...

myAudio.mute=true;  //to mute

myAudio.mute=false; //to un-mute

Hope this helps,
-Larry