T
T
TooMajot2021-01-31 21:54:27
Unity
TooMajot, 2021-01-31 21:54:27

How to access all "AudioSorce" in Unity3d?

There is a code by which I have to change the volume of the sounds of all AudioSources on the stage.

void Start()
    {
        AudioSource[] audioSources = GetComponents<AudioSource>();

        foreach (AudioSource audioSource in audioSources)
        {
            audioSource.volume = volume;
        }
    }


But this code doesn't work. Namely after "forech".
Before I used this method to find components on the same object, but I used:
Collider[] colliders = GetComponentsInChildren<Collider>();


I can assume that I just do not know how to find the components on the stage.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ReWire_92, 2021-02-01
@TooMajot

If you just want to change the volume of all sound sources in the scene to the same value, there is a way to do it much more correctly and simply:
AudioListener.volume

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question