Hi,
I’ve got a situation where I have a coroutine that can be called several times without being sure if the previous calls finished. My coroutine is like this:
System.Collections.IEnumerator DestroyDelayed(AudioSource audSrc, float length)
{
yield return new WaitForSeconds(length);
audSrc.Stop ();
_soundsPlaying.Remove(audSrc);
ObjectPoolManager.DestroyPooled(audSrc.gameObject);
Logger.Instance.Log("Deleting sound "+ audSrc.clip.name +". Now there are "+_soundsPlaying.Count+" sounds playing",DebuggingLevel.Warning);
}
This is part of my audio manager. This coroutine is started from a method that is called when I want to play a sound. This method creates a new object with an audio source and starts the previous coroutine code to let the object be destroyed after it has been finished playing.
As you see, this coroutine can be called before previous call finished executing. I’m looking for an obscure bug using the audio engine and would like to know if this could be the problem. When I call start coroutine is this modifying the local vars of the previous call or are they different?.
Thanks in advance.