game(scripts): normalise AudioLoop
This commit is contained in:
parent
4011266881
commit
b292de5922
1 changed files with 15 additions and 14 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue