- Home /
mute / unmute helps
i have wrote a script to mute it but it doesn't work here is that script
function Update() {
if(Input.GetKeyDown("1")) {
if(audio.mute)
audio.mute = false;
else
audio.mute = true;
}
}
and i need it to unmute when the same button is pressed again. any ideas?
thanks
Answer by khenkel · Sep 08, 2014 at 10:44 AM
Use this:
function Update()
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
audio.mute = !audio.mute;
}
}
It didn't recognize your "1" string. Also the muting is more clean now.
Answer by nikhil38 · Sep 08, 2014 at 10:58 AM
Though your question is not very clear ..But still if you need make a toggle sound button then you need to do following : 1. get a reference to audiosource 2. Save toggle state of your button (for eg. PlayerPref Script will do this saving stuff).
if you dont want to maintain state after the game/app is quit ...make use of static for saving states..
Your answer
Follow this Question
Related Questions
Audio Toggle,Toggle Audio After Game Object Is Enabled 0 Answers
mute/un-mute 1 Answer
Mute/Unmute not working with new sounds 2 Answers
how do i mute all audio sound? 3 Answers
Is there a way to create a random Audiosource loop? 2 Answers