I have two sound effects right now, one for the jump, and another for the music. I have an option in my options menu to where I can turn off the sound or music. When I turn off sound, everything turns off including the music. So how can I target only certain sounds/objects in the script? So far I use AudioListener.volume = 0; when I turn sound off. EDIT: If you read my latest comment(all the way at the bottom of the screen), you will see that I changed my script a little bit. I now have the music on a different script, on a different gameobject attached to the Player. Here’s my music script:
public class MusicTest : MonoBehaviour {
AudioSource audio; //variable
public AudioClip[] songs; //variable
int currentSong = 0; //variable
// Use this for initialization
void Start () {
audio = GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update () {
//This is for when I put more music
if (audio.isPlaying == false){
currentSong++;
if(currentSong >= songs.Length)
currentSong = 0;
audio.clip = songs[ currentSong ];
audio.Play();
}
}
}
My Jump sound is the same. Look at the replied comments for the script. I’ll re-post it and my menu to turn off sound and music again here when pastebin works again.
EDIT2: Okay pastebin is working again, so here’s my Jump Audio script(the code you are about to see is part of the Player script): http://pastebin.com/2NRKyyaH
And now for the Sound Menu script, which is where I want the sound to either turn off or on without affecting the music: http://pastebin.com/5agXeq65
As for the music menu, it is almost exactly the same as the sound, so I won’t be posting it.
Sorry for all these edits. I just want to make sure everyone knows how my scripts work(though it’s understandable if you still don’t). Please help if you have time. Thanks.