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
|
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,16 +21,20 @@ public class AudioLoop : MonoBehaviour
|
||||||
{
|
{
|
||||||
StartCoroutine(PlayPauseLoop());
|
StartCoroutine(PlayPauseLoop());
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator PlayPauseLoop()
|
private IEnumerator PlayPauseLoop()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
audioSource.Stop();
|
audioSource.Stop();
|
||||||
audioSource.Play(); // Play the audio
|
audioSource.Play(); // Play the audio
|
||||||
yield return new WaitForSeconds(10f); // Play for 10 seconds
|
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
|
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