I want access to (for example) all AudioSources in Unity and stop all sounds.
using UnityEngine;
using System.Collections;
public class StopAllSound: MonoBehaviour {
void Start() {
AudioSource[] allMyAudioSources = GetComponents<AudioSource>();
allMyAudioSources.Stop();
}
}
This does not work, because of the followin error:
Assets/SlowMotion.cs(8,35): error CS1061: Type `UnityEngine.AudioSource[]' does not contain a definition for `Stop' and no extension method `Stop' of type `UnityEngine.AudioSource[]' could be found (are you missing a using directive or an assembly reference?)
I try it by FindObjectsOfType:
using UnityEngine;
using System.Collections;
public class SlowMotion : MonoBehaviour {
void Start() {
AudioSource[] allAudioSources = UnityEngine.Object.FindObjectsOfType<AudioSource>();
allAudioSources.Stop();
}
}
but I get the same error.