- Home /
Can I play multiple positioned audiosources with one game object?
Hi,
I am creating a scene with 160 recorded ambient sounds. Each audio source for a different position in the scene. The problem is I am exceeding the playing limit of 100 audio channels. Because the ambient sounds must be played simultaneously to stay synchronized, I created groups of audio sources to be played simultaneously. Can I add these groups of audio sources with their component properties to a new empty game object so that the audio sources attached play simultaneously when the game controller collides with the new game object (each one from their own position)? Is it possible to make the audio clips play from the last played position and not from the beginning of the clip each time when the audio source is called to play?
Answer by chaguaramo · Apr 03, 2014 at 10:10 PM
Hi, here is a script that solve my first question and makes it possible to create audio zones with a random form. Thanks to Daniel Murcia!
For use it, create a surface with the form you need and place it on the floor level, add a mesh collider, select-on the is trigger option, unselect the mesh render option and attach to the surface you have created the audio sources you want to be played simultaneously when enter in the zone designed by your surface.
So you can differentiate audio zones that are played at once when are triggered.
#pragma strict
var audioSources;
function Start(){
audioSources = gameObject.GetComponentsInChildren(AudioSource);
}
function OnTriggerExit(){
Debug.Log("stopping sounds");
Debug.Log(this);
var self = this;
for (var source:AudioSource in audioSources) {
Debug.Log(source);
source.Stop();
}
}
function OnTriggerEnter(){
Debug.Log("starting sounds");
Debug.Log(this);
var self = this;
for (var source:AudioSource in audioSources) {
Debug.Log(source);
source.Play();
}
}