Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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();
            }
        }
        
        }
Comment

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();
     }
 }
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# get project directory 
Csharp :: c# format string with 2 decimals 
Csharp :: require admin privileges c# 
Csharp :: unity how to add force 
Csharp :: delay in unity 
Csharp :: C# console app how to run another program 
Csharp :: unity how to summon an object with code 
Csharp :: even number checker in c# 
Csharp :: how to choose a random child in a gameobject unuity 
Csharp :: base64decode C# 
Csharp :: c# copy list without reference 
Csharp :: unity find closest point on line 
Csharp :: {} is this used for code blcoks in c# 
Csharp :: serializefield for animator 
Csharp :: unity get velocity of gameobject 
Csharp :: load prefab in script unity 
Csharp :: unity check if audio playing 
Csharp :: c# console writeline array 
Csharp :: unity check if gameobject is active 
Csharp :: game object set exact position unity 
Csharp :: textbox only numbers c# 
Csharp :: string from byte array c# 
Csharp :: c# read next int Like Java 
Csharp :: C# get enum value by DescriptionAttribute 
Csharp :: how to convert iformfile to byte array c# 
Csharp :: c# datetime now timestamp 
Csharp :: c# @ before string 
Csharp :: check strings is equal shell 
Csharp :: c# clear a textbox 
Csharp :: c# split string into characters 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =