Mute button

I would like to make a Mute button on the game scene that will mute all sounds and when hit the second time it will un-mute.Can I get some instructions on how to do this along with help with the scripting?

you can do a button and if it is pressed, disable the audio Listener component from your Main Camera,
to un-mute, just enable the component again… The Audio Listener represents all the audio system in your game, without audio listener there will be no sound… :wink:

var canMute : boolean = true;  //Initial state is true
var theListener : AudioListener;

function Start () {
theListener = GameObject.Find("Main Camera").GetComponent(AudioListener);
}

function OnMouseUp () {
if (canMute){
   //The audio is muted
   canMute = false;
   theListener.enabled = false;
   }
else{
   //The audio works again
   canMute = true;
   theListener.enabled = true;
   }
}

Wat kind of script do i use ? Do i use the script on the Camera or on some Object ? This is going to be used for iphone app < i just want to know if it would mute the music from the apple Music or if it does it to just the game it self only ?

I tried it but did not work.

no, you must to set this script on the button … is a guiTexture button?
make sure you have a camera in your hierarchy panel called “Main Camera” and have Audio Listener attached to it…

hmm, i guess no matter if you use for iphone… (i think)… …

how should i make the button should i replace it for the function OnMouseUp() on the script you provided me

you have two ways, the first one is creating a guiTexture, the second is with OnGUI function, i think you have more control with the first one… here is the way :

add a component → GUITexture
set the transform positions X, Y and Z of your screen, and set the pixel inset width height to 0 so the guiTexture can fix your screen perfectly… then scale your guiTexture (transform scale) to get the desired size…

to that guiTexture, attach the script above… and try, if works, then you can add two more functions to the script to get better results (actually there is no need to do this… just to get best experience)

OnMouseEnter and OnMouseExit…