Reputation: 3353
have Toggle on/off for mute volume and this is my function :
public void Mm(bool vv)
{
if (vv)
{
AudioListener.volume = 0;
}
else
{
AudioListener.volume = 1;
}
}
all thing work well but problem is : when i mute and go another scene , when come back in this scene again volume not mute!
Upvotes: 1
Views: 212
Reputation: 10720
Create a SoundManager
script like below and place it in your current scene :
public class SoundManager : MonoBehaviour
{
void OnEnable()
{
AudioListener.volume = PlayerPrefs.GetFloat("volume",0);
}
void OnDisable()
{
AudioListener.volume = 1;
}
public void Mute(bool vv)
{
if (vv)
{
AudioListener.volume = 0;
}
else
{
AudioListener.volume = 1;
}
PlayerPrefs.SetFloat("volume",AudioListener.volume);
PlayerPrefs.Save()
}
}
Upvotes: 2