2025-02-10 23:04:02 +08:00
|
|
|
/*
|
2025-02-14 21:55:58 +08:00
|
|
|
Author: Wai Lam
|
|
|
|
Date: 10/2/2025
|
|
|
|
Description: Loop the school bell and interval
|
2025-02-10 23:04:02 +08:00
|
|
|
*/
|
2025-02-14 21:55:58 +08:00
|
|
|
|
2025-02-10 23:04:02 +08:00
|
|
|
using System.Collections;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class AudioLoop : MonoBehaviour
|
|
|
|
{
|
|
|
|
public AudioSource audioSource; // Attach your AudioSource in the Inspector
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2025-02-14 21:55:58 +08:00
|
|
|
if (audioSource == null) audioSource = GetComponent<AudioSource>();
|
2025-02-10 23:04:02 +08:00
|
|
|
StartCoroutine(PlayPauseLoop());
|
|
|
|
}
|
2025-02-14 21:55:58 +08:00
|
|
|
|
|
|
|
public void StartAudioLoop()
|
2025-02-12 21:01:29 +08:00
|
|
|
{
|
|
|
|
StartCoroutine(PlayPauseLoop());
|
|
|
|
}
|
2025-02-14 21:55:58 +08:00
|
|
|
|
2025-02-10 23:04:02 +08:00
|
|
|
private IEnumerator PlayPauseLoop()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2025-02-14 21:55:58 +08:00
|
|
|
audioSource.Stop();
|
|
|
|
audioSource.Play(); // Play the audio
|
2025-02-10 23:04:02 +08:00
|
|
|
yield return new WaitForSeconds(10f); // Play for 10 seconds
|
|
|
|
|
2025-02-14 21:55:58 +08:00
|
|
|
audioSource.Stop(); // Pause the audio
|
2025-02-10 23:04:02 +08:00
|
|
|
yield return new WaitForSeconds(15f); // Pause for 15 seconds
|
|
|
|
}
|
2025-02-14 21:55:58 +08:00
|
|
|
|
|
|
|
// NOTE: are we really just going to let this stay alive forever
|
|
|
|
// ReSharper disable once IteratorNeverReturns
|
2025-02-10 23:04:02 +08:00
|
|
|
}
|
2025-02-14 21:55:58 +08:00
|
|
|
}
|