Skip to content

Commit

Permalink
feat: decrease pitch as we run out of oxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoneerC committed Sep 23, 2024
1 parent ccb85b2 commit a8dfbca
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Assets/Scripts/WaterLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private void Start()
_previousWaitTime = GetWaitTime();
_audioSource = GetComponent<AudioSource>();
blackFadeImage.color = new Color(0f, 0f, 0f, 0f);

_audioSource.volume = 1.0f;
}

Expand Down Expand Up @@ -98,6 +97,8 @@ private IEnumerator OxygenDecrement()
_previousWaitTime = currentWaitTime;
}

UpdateBreathingPitch();

switch (currentOxygen)
{
case <= 6 when !_hasPlayedWarning3:
Expand Down Expand Up @@ -134,6 +135,12 @@ private IEnumerator OxygenDecrement()
}
}

private void UpdateBreathingPitch()
{
float normalizedOxygen = (float)currentOxygen / maxOxygen;
_audioSource.pitch = Mathf.Lerp(0.5f, 1.5f, normalizedOxygen);
}

private static IEnumerator FadeTextAlpha(TextMeshProUGUI text, float startAlpha, float endAlpha, float duration)
{
var elapsedTime = 0f;
Expand All @@ -150,7 +157,6 @@ private static IEnumerator FadeTextAlpha(TextMeshProUGUI text, float startAlpha,
text.color = new Color(color.r, color.g, color.b, endAlpha);
}


private IEnumerator RestoreOxygen()
{
const float lerpDuration = 5f;
Expand Down Expand Up @@ -201,7 +207,7 @@ private IEnumerator FadeOutBlackCanvas()
while (timeElapsed < duration)
{
timeElapsed += Time.deltaTime;
var alpha = Mathf.Clamp01(1 - (timeElapsed / duration)); // Fade out
var alpha = Mathf.Clamp01(1 - (timeElapsed / duration));
blackFadeImage.color = new Color(0, 0, 0, alpha);
yield return null;
}
Expand All @@ -210,7 +216,6 @@ private IEnumerator FadeOutBlackCanvas()
_isFadingIn = false;
}


private void EnterWater()
{
_isUnderwater = true;
Expand Down

0 comments on commit a8dfbca

Please sign in to comment.