# delayed countdown timer

**URL:** <https://discussions.unity.com/t/delayed-countdown-timer/794512>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [June 6, 2020, 1:14am UTC](https://discussions.unity.com/t/delayed-countdown-timer/794512 "2020-06-06T01:14:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamukamm](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@kamukamm](https://discussions.unity.com/u/kamukamm)\
**Post date:** [June 6, 2020, 1:14am UTC](https://discussions.unity.com/t/delayed-countdown-timer/794512/1 "2020-06-06T01:14:43Z")

</div>

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[&nbsp;] 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;  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)\
**Post date:** [June 6, 2020, 3:24am UTC](https://discussions.unity.com/t/delayed-countdown-timer/794512/2 "2020-06-06T03:24:41Z")

</div>

Please use code tags: [Using code tags properly](https://discussions.unity.com/t/481379)
