missle firing loop, need help to resolve

function FireMissle(){
    var ranMissleCount:int = Random.Range(1,4);
    for(i=0;i< ranMissleCount;i++){
        var clone:GameObject = Instantiate(Missle, missleSpawnPoint.transform.position, missleSpawnPoint.rotation);
        yield WaitForSeconds (.6);
    }
    FireMissleDelay();
}

function FireMissleDelay(){
    var ran:float = Random.Range(3,6);
    yield WaitForSeconds (ran);
    FireMissle();
}

so i wanted to have 1-3 missles fire every 3 to 6 seconds until the firing unit is destroyed.

i thought the above two function would accomplish that with a loop stepping ahead in time with yields, but that’s not accepted by the compiler.

before i fall back on a boolean to adjust states can anyone help me with a more efficient way of pulling this off?

It doesn’t need to be two functions, unless you need to be able to choose which one to call first in different circumstances. But otherwise, I don’t immediately see any problem with what you have, at least in principle.

You didn’t mention what the compile error was though, so I may have missed something trivial.

In my experience compiler won’t let you play with recursive coroutines. That might be because I’m not that good in this javascript.

But you can get your missile shooting to work with one function:

private var stillFiring : boolean = true;

function FireMissles()
{
  var ranMissleCount:int = 0;
  while(stillFiring) // or while(true) if you don't want to set state
  {
    ranMissleCount = Random.Range(1,4);
    for(i=0;i< ranMissleCount;i++)
    {
      var clone:GameObject = Instantiate(Missle, missleSpawnPoint.transform.position, missleSpawnPoint.rotation);
      yield WaitForSeconds (.6);
    }
    yield WaitForSeconds (Random.Range(3.0,6.0));
  }
}