Hello all,
Hope everyone is doing well? I have this small problem. I have created a mute/unmute button for my game, whereby it changes color (red) when turned on and to (white) when off. The music track plays fine, albeit for one hiccup. The track restarts whenever I unmute the sound.
Here is my code for the function. By the way I am using a button to switch between mute and unmute. I would like to know how I can get the music to play at the precise moment I muted it at.
//FUNCTION TO MUTE AND UNMUTE MUSIC
public void MuteMenuMusic()
{
if (IsMusicMuted == false)
{
CurrentSoundImage.color = Color.red; //CHANGE BUTTON COLOR TO RED
AudioSourcePlayer.mute = !AudioSourcePlayer.mute; //MUTE MUSIC
IsMusicMuted = true;
}
else if (IsMusicMuted == true)
{
AudioSourcePlayer.PlayScheduled(0.00f);
AudioSourcePlayer.mute = !AudioSourcePlayer.mute; //UNMUTE MUSIC
CurrentSoundImage.color = Color.white; //CHANGE BUTTON COLOR TO WHITE
IsMusicMuted = false;
}
Thank you to all, and happy coding. ![]()