Stop audio playing after a timer reset

Hi I am very new to all this and have tried to solve most of my problems myself but I’m stuck on how to add in a 2nd condition to this Jscript.

I use 3 scripts.

I have an add time script which adds +10 seconds of time on an item pickup to two other scripts one counts down to 0 and restarts the level and one plays a audio file at 0 seconds but the countdown is 7 so the audio plays with 3 seconds of the level time left.

I want to add a condition into the audio script so the sound is stopped if the timer goes back above 0 (3 seconds level time)

I originally had 1 timer script but again got stuck on how the ‘if’ conditions worked. This solved one problem but created another.

Thanks in advance.

#pragma strict
var countdown : AudioClip;
var timer2 : float = 7.0;


function Update()
{
	timer2 -= Time.deltaTime;
	
	
	if(timer2 <= 0)
	
	{
	
	timer2 = 0;
	AudioSource.PlayClipAtPoint(countdown, transform.position);
	Destroy(gameObject);
		
			
		
	}
}

Managed to solve this myself.

	if(timer2 > 0.0f)
    {
    	audio.Stop(); 
    }
 
    else if(timer2 <= 0.0f)
    {
 if (!audio.isPlaying){
			audio.clip = countdown;
			audio.Play();

Switch your if statements around like this. That way your application will stop the audio until the timer is up. If the timer jumps back up above zero by any amount (1, 2 or 10 seconds etc) it should automatically stop the audio. I doubt it will be a graceful stop but you can investigate this yourself later.

Loop is below

if(timer2 > 0.0f)
{
   AudioSource.Stop();
}
else if(timer <= 0.0f)
{
  AudioSource.PlayClip etc..
}