/// <summary> /// Create sounds with delay based on the data inside the sound effect /// </summary> /// <param name="data"></param> /// <returns></returns> public IEnumerator DelaySounds(SoundEffectData data) { yield return(new WaitForSeconds(data.soundTriggerTime)); //spawn the sound AudioCreator.CreateTemporarySound(data); }
//Create audio source as child in scene and destroy after clip duration public static void CreateTemporarySound(SoundEffectData data) { AudioSource source = CreateSound(data.audioClip); source.volume = data.volume; //random pitching if (data.useRandomPitch) { //determine the pitch according to min and max settings float pitch = Random.Range(data.randomPitch[0], data.randomPitch[1]); source.pitch = pitch; } //automatically destroy Destroy(source.gameObject, data.audioClip.length + safetyTailDuration); }