Make an Array of Particles emit at the same time

Here’s the script:

var BParticles: ParticleEmitter[];

function Start () {
    for (var particles in BParticles){
        particles.emit = true;
        yield WaitForSeconds (Random.Range(5.0, 10.0));
        particles.emit = false;
    }
}

The problem is that the particles don’t emit at the same time…
Any help would be appreciated

The problem is that you are using yield WaitForSeconds(whatev) in the middle of your for loop! What is happening here, is it is cycling through your particle systems, turning each one on one at a time (which is actually kind of more sophisticated behaviour than what you were aiming for here…)

You should rearrange it so that the WaitForSeconds bit only happens once-

function Start () {
    for (var particles in BParticles){
        particles.emit = true;
    }
    yield WaitForSeconds (Random.Range(5.0, 10.0));
    for (var particles in BParticles){
        particles.emit = false;
    }
}

This way, it’ll turn everything on, wait for a few seconds, then turn everything back off again.

If that’s not what you want, and instead you want all the particle systems to have a different wait time, you could use a coroutine!

function Start () {
    for(var particles in BParticles)
    {
        StartCoroutine(OnOffParticles(particles));
    }
}

function OnOffParticles(var emitter : ParticleEmitter)
{
    emitter.emit = true;
    yield WaitForSeconds (Random.Range(5, 10));
    emitter.emit = false;
}

That will set a different, random timer on each particle system.