How do I make it so that an Audio Source in a Prefab is controlled by an In-Game Button?,

I’m relatively new to coding so if this seems like it’s a stupid question… it probably is.

I have two different scenes, the Game Play scene and the Main Menu scene. When the user clicks a player on the Main Menu scene a prefab of the selected player loads into the Game Play scene.

My problem is with the Sound Effects Button.

When the player jumps he makes a jumping sound. I want to make it so that when I press the Sound Button the Audio Source “Jump” inside the player gets muted, and when I press it again it gets unmuted.

The player can only jump when he is touching the floor.

    if (Input.GetButtonDown("Jump") && isGrounded)
        myBody.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);

Functions of Sound Effects On
Functions of Sound Effects Off

With these functions the Player 1 Audio Source and the Player 2 Audio Source don’t seem to be working properly.

You can do that by setting AudioSource.mute. But you need to make a variable for the AudioSource, you can’t just call AudioSource.mute. Set the button OnClick to execute the MuteMySource() function.

AudioSource mySource;

void MuteMySource()
       mySource.mute = true;


void UnMuteMySource()
       mySource.mute = false;