Why does this not work?

Hi,

Why does the first script not work but the second one does by calling pauseFlightPath01 first then calling pauseFlightPath02 ?

#pragma strict

var minWaitTime : int;			// Minimum time to pause flightpath
var maxWaitTime : int;			// Maximum time to pause flightpath
var planeSound : AudioClip;
var useFlightPath : GameObject;	// Flighpath to send message to

function Awake(){

}

function Start() {

	audio.volume = 0.5;
	audio.loop = true;
	audio.clip = planeSound;
	audio.Play();
	Invoke("pauseFlightPath02", 0);
}

function Update () {

}

function pauseFlightPath02(){

	var randomWaitTime : float = Random.Range(minWaitTime, maxWaitTime );

		yield WaitForSeconds (20); // Length to end of flightpath
		audio.Stop();
		useFlightPath.SendMessage("Pause");
		yield WaitForSeconds (randomWaitTime);
		audio.Play();
		useFlightPath.SendMessage("Play");

	Invoke("pauseFlightPath02", 0);
}

#pragma strict

var minWaitTime : int;		// Minimum time to pause flightpath
var maxWaitTime : int;		// Maximum time to pause flightpath
var planeSound : AudioClip;
var useFlightPath : GameObject;	// Flighpath to send message to

function Awake(){

}

function Start() {

	audio.volume = 0.5;
	audio.loop = true;
	audio.clip = planeSound;
	audio.Play();
	Invoke("pauseFlightPath01", 0);	
}

function Update () {

}

function pauseFlightPath01(){

	pauseFlightPath02();
}

function pauseFlightPath02(){

	var randomWaitTime : float = Random.Range(minWaitTime, maxWaitTime );

		yield WaitForSeconds (20); // Length to end of flightpat
		audio.Stop();
		useFlightPath.SendMessage("Pause");
		yield WaitForSeconds (randomWaitTime);
		audio.Play();
		useFlightPath.SendMessage("Play");

	Invoke("pauseFlightPath01", 0);
}

I haven’t tested it in UnityScript yet, but it shouldn’t be possible to invoke a coroutine. You’re using yield in your function which makes it a coroutine.