Hello,
I’ve been working at this for 2 days and I’ve had some great help, but it seems like something isn’t working right. I am using this script to toggle the mute parameter on an Audio Source:
// Mutes-Unmutes the sound of this transfor each time the user presses escape.
function Update() {
if(Input.GetKeyDown(KeyCode.Escape)) {
if(audio.mute)
audio.mute = false;
else
audio.mute = true;
}
}
This script works perfectly for muting the audio source, but it doesn’t seem to unmute the audio. Basically, if I start the scene with the mute button ticked on the audio source, it will not unmute the audio source and toggle the mute button each time I press escape. The check-mark on the mute parameter stays ticked on the audio source and no audio plays. If anybody could please help me out on this one, I would really appreciate it! Trust me, I’ve spent a ton of time on this one, and I just can’t figure it out! THANK YOU SO MUCH for your help!!
Did you try using GetKeyUp instead of GetKeyDown? It could be rapidly toggling on and off.
– cmpgk1024I'll give it a go. Be right back.
– Peanut97Is there a way to make it toggle the mute when the button is not held down, just tapped?
– Peanut97That's what GetKeyUp should do. GetKeyDown will return true whenever the key is held down, so you'll be toggling it constantly whenever the escape key is held. If you use GetKeyUp it won't return true until the key is released, so that should work if you want to have it toggle when the button is tapped.
– cmpgk1024I changed it to GetKeyUp and it seems like the audio will play whenever the button is held. I'm sure what's going wrong.
– Peanut97