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
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<AudioSource>();
}
if (audioSource == null) audioSource = GetComponent<AudioSource>();
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
}
}
}