- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Bernardo01 · Oct 01, 2016 at 06:56 AM ·
c#audiosourceaudiolistener
How to mute Backgroundmusic while other audiosources still plays
I have a problem on muting the BGM because i am muting the audiolistener and i dont know what to do to mute only the specific audiosource. Heres my code; using UnityEngine; using System.Collections; using UnityEngine.UI;
public class MusicGenerator : MonoBehaviour {
public GameObject music;
void Start () {
int a = PlayerPrefs.GetInt ("music");
Debug.Log (a);
if (a == 0) {
AudioListener.volume = 0;
PlayerPrefs.SetInt ("music", 0);
} else{
AudioListener.volume = 1;
PlayerPrefs.SetInt ("music", 1);
}
// the GameController is the tag for the backgroundmusic
GameObject g = GameObject.FindGameObjectWithTag ("GameController");
if (!g) {
Instantiate (music, Vector3.zero, Quaternion.identity);
}
}
// Update is called once per frame
void Update () {
}
public void Mute(){
int h = PlayerPrefs.GetInt ("music");
Debug.Log (h);
if (h == 0) {
AudioListener.volume = 1;
PlayerPrefs.SetInt ("music",1);
} else {
AudioListener.volume = 0;
PlayerPrefs.SetInt ("music",0);
}
}
}
capture.png
(168.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
SetActive on a different gameObject's component? Audio Source 1 Answer
Unity 5 and Multiple AudioListeners 2 Answers
Delayed Button Sounds 0 Answers