- Home /
Audio problems, how to turn up and down specifik audio sources?
So in having problems with audio, I want it to be so that when i click a button the sounds starts and it keep looping since it is suppose to be music, that is easy, but im having a hard time turning off the music when i click another button, because i want to turn off a specifik piece of audio not all of the audio in my game. Please ask if you want to know more about the problem :)
I code in C# but i can translate JavaScript if needed.
Answer by Fornoreason1000 · May 09, 2013 at 09:55 PM
ok, first you find the audio sources this can be done with
gameObject.GetComponent();
then just disable/enable it and adjust the volume. with
mySoundSource.enable = false
//or
mySoundSource.volume = 0.2;
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource-volume.html
http://docs.unity3d.com/Documentation/ScriptReference/Behaviour-enabled.html?from=AudioSource
you can also use Stop() and Pause()
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.Stop.html
http://docs.unity3d.com/Documentation/ScriptReference/AudioSource.Pause.html
if an audio source is attached to the same gameobject as you script you can reference it with
audio
hope it helps
Your answer
![](https://koobas.hobune.stream/wayback/20220613101922im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Passing Java String to C# for use in Wwise Post Event = Fail 0 Answers
Distribute terrain in zones 3 Answers
Play music trough scenes 0 Answers
Multiple Cars not working 1 Answer