Hello i have a menu scene where i have a mute button and a empty gameobject with audiosource and dontdestroyonload script attached to it. Here is the code from the gameobject.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Backgorund_Music_Manger : MonoBehaviour
{
AudioSource ads;
public GameObject BackgroundMusic;
bool play_sound = true;
void Awake()
{
ads = GetComponent<AudioSource>();
if(SceneManager.music == true)
{
Destroy(this.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
}
SceneManager.music = true;
}
void Update()
{
if(SceneManager.currentScene == 4)
{
ads.volume = 0.1f;
}
else
{
ads.volume = 1f;
}
}
public void stop_sound()
{
ads = GetComponent<AudioSource>();
if(play_sound == true)
{
ads.Pause();
play_sound = false;
}
else
{
ads.Play();
play_sound = true;
}
}
}
after going back to menu the mute button stops working.
Help