- Home /
Question by
Griffo · Oct 03, 2012 at 11:40 AM ·
yieldwaitforsecondsinvoke
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);
}
Comment
I know this might be reaching but could it be the randomWaitTime being established several times? I'm not familiar with how Invokes but it could be getting passed along - do you get any errors?
Does it even get to the invoke, maybe the fault is somewhere else and some variables are just messed up?
The second one works fine going through pauseFlightPath01, no I don't get errors just don't work.
Answer by Dreamblur · Oct 03, 2012 at 11:52 AM
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.