game(scripts): normalise AudioLoop

This commit is contained in:
Mark Joshwel 2025-02-14 21:55:58 +08:00
parent 4011266881
commit b292de5922

View file

@ -1,10 +1,10 @@
/* /*
Author : Wai Lam Author: Wai Lam
Date : 10/2/2025 Date: 10/2/2025
Description : Loop the school bell and interval Description: Loop the school bell and interval
*/ */
using System.Collections; using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class AudioLoop : MonoBehaviour public class AudioLoop : MonoBehaviour
@ -13,10 +13,7 @@ public class AudioLoop : MonoBehaviour
private void Start() private void Start()
{ {
if (audioSource == null) if (audioSource == null) audioSource = GetComponent<AudioSource>();
{
audioSource = GetComponent<AudioSource>();
}
StartCoroutine(PlayPauseLoop()); StartCoroutine(PlayPauseLoop());
} }
@ -24,6 +21,7 @@ public class AudioLoop : MonoBehaviour
{ {
StartCoroutine(PlayPauseLoop()); StartCoroutine(PlayPauseLoop());
} }
private IEnumerator PlayPauseLoop() private IEnumerator PlayPauseLoop()
{ {
while (true) while (true)
@ -35,5 +33,8 @@ public class AudioLoop : MonoBehaviour
audioSource.Stop(); // Pause the audio audioSource.Stop(); // Pause the audio
yield return new WaitForSeconds(15f); // Pause for 15 seconds 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
} }
} }