how can i mute all audio sources in the scene?

I already have a script attached to all the components that has an audio source, like the background music, the player’s sounds and the enemy, who is a prefab. all sounds get mute when i press M, except for the enemy’s sounds (hurt and death sounds). that’s my script (c#):

using UnityEngine;
using System.Collections;

public class Audio : MonoBehaviour {

AudioSource audio;

void Start() {
	audio = GetComponent<AudioSource>();
}

void Update() {
	if (Input.GetKeyDown(KeyCode.M))
	if (audio.mute)
		audio.mute = false;
	else
		audio.mute = true;

}

}

how can i mute the enemy sounds as well?

Why not just mute the audio listener? That way all sounds are muted at once.

	public void ToggleSound()
	{
		toggle = !toggle;

		if (toggle)
			AudioListener.volume = 1f;

		else
			AudioListener.volume = 0f;
	}

I would use one “Mute manager” instead of multiple attached to each objects.

FindObjectsOfType is not resources efficient, and maybe, you can “cache it” instead of retrieving them each time. It depends on your project.

public class MuteManager : MonoBehaviour {

    private bool muted ;
 
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.M))
            ToggleAudio();
    }
    
    public void DisableAudio()
    {
       SetAudioMute( false ) ;
    }
    
    public void EnableAudio()
    {
       SetAudioMute( true ) ;
    }
    
    public void ToggleAudio()
    {
        if( muted )
            DisableAudio();
        else
            EnableAudio();
    }
    
    private void SetAudioMute( bool mute )
    {
        AudioSource[] sources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
        for( int index = 0 ; index < sources.Length ; ++index )
        {
            sources[index].mute = mute ;
        }
        muted = mute ;
    }
}