From b8ed2b9fa2446c24bf0232d446c7350037f17e01 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Wed, 4 Oct 2023 17:56:01 +0200 Subject: [PATCH] done (#558) --- Assets/Scripts/Util/Sound.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index 89b88932..09c3b538 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -43,6 +43,23 @@ namespace HeavenStudio.Util { } + public void LerpVolume(double beat, double length, float volumeStart, float volumeEnd) + { + if (!gameObject.activeSelf) return; + StartCoroutine(LerpVolumeCo(beat, length, volumeStart, volumeEnd)); + } + + private IEnumerator LerpVolumeCo(double beat, double length, float volumeStart, float volumeEnd) + { + float normalized = 0; + while (normalized <= 1) + { + normalized = cond.GetPositionFromBeat(beat, length); + audioSource.volume = Mathf.Lerp(volumeStart, volumeEnd, normalized); + yield return null; + } + } + public void Play() { if (!available)