I need some help. I currently have a list of audio sources that are playing in sequential order with a 30-second delay in between each audio source. I would like to have a countdown timer that displays the seconds left before the next audio plays. My current countdown timer is counting the 30-seconds while the audio source is playing and is not correct.
This is my script for the delayed audio played sequentially.
public class playdelayedaudio : MonoBehaviour
{
private AudioSource s;
public AudioClip[ ] ListAudioClips;
int index = 0;
bool MoveToNextAudio = false;
private float timer = 0.0f;
private float counter = 0.0f;
public float waitingTime = 5.0f;
void Start()
{
s = this.GetComponent();
s.clip = ListAudioClips[0];
s.Play();
}
// Update is called once per frame
void Update()
{
if (MoveToNextAudio)
{
s.clip = ListAudioClips[index];
s.Play();
MoveToNextAudio = false;
timer = 0;
counter = 0;
}
if (!s.isPlaying)
{
timer += Time.deltaTime;
if (timer > waitingTime)
{
if (index < ListAudioClips.Length)
{
index++;
}
MoveToNextAudio = true;
}
else
{
//DisplayTimer here
counter += Time.deltaTime;
Debug.Log((int)counter);
}
}
}
}
And this is my script for the countdown timer.
public class CountdownTimer : MonoBehaviour
{
float currentTime = 0f;
float startingTime = 30f;
int timerCount = 1;
[SerializeField] Text countdownText;
void Start()
{
currentTime = startingTime;
}
void Update()
{
currentTime -= 1 * Time.deltaTime;
int minutes = Mathf.FloorToInt(currentTime / 60F);
int seconds = Mathf.FloorToInt(currentTime - minutes * 60);
countdownText.text = string.Format(“{0:00}:{1:00}”, minutes, seconds);
if (currentTime <=0)
{
currentTime = startingTime;
}
}
}