From b292de5922fc633f978d2844f0fe3a96c3a1b89a Mon Sep 17 00:00:00 2001 From: Mark Joshwel Date: Fri, 14 Feb 2025 21:55:58 +0800 Subject: [PATCH] game(scripts): normalise AudioLoop --- Game/Assets/Scripts/AudioLoop.cs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Game/Assets/Scripts/AudioLoop.cs b/Game/Assets/Scripts/AudioLoop.cs index 5295c7a..16ae5f8 100644 --- a/Game/Assets/Scripts/AudioLoop.cs +++ b/Game/Assets/Scripts/AudioLoop.cs @@ -1,10 +1,10 @@ /* - Author : Wai Lam - Date : 10/2/2025 - Description : Loop the school bell and interval + Author: Wai Lam + Date: 10/2/2025 + Description: Loop the school bell and interval */ + using System.Collections; -using System.Collections.Generic; using UnityEngine; public class AudioLoop : MonoBehaviour @@ -13,27 +13,28 @@ public class AudioLoop : MonoBehaviour private void Start() { - if (audioSource == null) - { - audioSource = GetComponent(); - } + if (audioSource == null) audioSource = GetComponent(); StartCoroutine(PlayPauseLoop()); } - - public void StartAudioLoop() + + public void StartAudioLoop() { StartCoroutine(PlayPauseLoop()); } + private IEnumerator PlayPauseLoop() { while (true) { - audioSource.Stop(); - audioSource.Play(); // Play the audio + audioSource.Stop(); + audioSource.Play(); // Play the audio yield return new WaitForSeconds(10f); // Play for 10 seconds - audioSource.Stop(); // Pause the audio + audioSource.Stop(); // Pause the audio yield return new WaitForSeconds(15f); // Pause for 15 seconds } + + // NOTE: are we really just going to let this stay alive forever + // ReSharper disable once IteratorNeverReturns } -} +} \ No newline at end of file