I have searched and see numerous ideas about this but the JS code I try only ever seems to control one (1st one) audio source volume on my game object, I have 3 audio sources on this game object.
In C#, you’d want to do something like the following:
AudioSource[] asc;
void Start() {
asc = GetComponents<AudioSource>();
}
public void SetVolume(float vol) {
for (int i = 0; i < asc.Length; i++) {
asc*.volume = vol;*
} } I can’t say exactly for Js, but it’s very similar. In the Start() method you’re gathering all of the AudioSource components on that specific object (not looking in child objects). You only want to do this once to save on performance. In SetVolume(), you would call this method with the volume level you want. It then iterates through all of the AudioSource components it has found and sets their volume.