unity stop all audio

Code Example - unity stop all audio

                
                        // unity stop all sound by yasin
 private var allAudioSources : AudioSource[];
  
 function Awake() {
     allAudioSources = FindObjectsOfType(AudioSource) as AudioSource[];
 }
  
 function StopAllAudio() {
     for(var audioS : AudioSource in allAudioSources) {
         audioS.Stop();
     }
 }
                    
                
 

stop audio unity

                        
                                using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public AudioSource MyAudioSource; //put your object in inspector that have the audio


void Update(){


if (Input.GetKeyDown(KeyCode.Escape)) //When press ESC to pause the game
        {
            if (Time.timeScale == 0)
            {
                MyAudioSource.Stop();
            }
            else
            {
                MyAudioSource.Play();
            }
        }
        
        }
                            
                        
 

stop sound in unity

                        
                                audioSource.Play();//Start playing
audioSource.Stop();//Stop playing