void OnEnable() { if (source == null) { source = gameObject.AddComponent <AudioSource>(); } AudioTrigger.configureSource(fx, source); source.loop = true; source.Play(); }
public void VolumeFade(AudioTrigger audioTrigger, AudioSource audioSource, float targetVol, float fadeTime) // configures and triggers the fade procedure { volFadeStart = vol; volFadePath = targetVol * audioTrigger.volume - volFadeStart; // targetVol=1, the target is not 1, but is equal to volumeStart timeFadeDuration = fadeTime; timeFadeStart = Time.time; if (volFade != null) { StopCoroutine(volFade); } volFade = VolFade(audioSource); StartCoroutine(volFade); }
public static float configureSource(AudioTrigger trigger, AudioSource source, float volumeScale = 1f, float pitchScale = 1f) { source.clip = trigger.Clip; source.outputAudioMixerGroup = trigger.channel; source.volume = trigger.volume * volumeScale; if (trigger.useRandomPitch) { source.pitch = Random.Range(trigger.randomPitch.x, trigger.randomPitch.y) * trigger.pitch; } else { source.pitch = trigger.pitch * pitchScale; } source.spatialBlend = trigger.soundType == SOUND_TYPE.EMIT_3D ? 1f : 0f; source.minDistance = trigger.minDistance; source.maxDistance = trigger.maxDistance; return(source.clip != null ? source.clip.length + 0.5f : 0f); }
public void triggerEffect(AudioTrigger fx) { }