x


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

more ▼

asked Oct 17 '11 at 01:49 AM

xDeltax gravatar image

xDeltax
1 2 2 2

(Fixed your formatting because I hate bad formatting)

Oct 17 '11 at 01:53 AM syclamoth

Thank you

Oct 17 '11 at 02:15 AM xDeltax
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

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.

more ▼

answered Oct 17 '11 at 01:56 AM

syclamoth gravatar image

syclamoth
15k 7 15 80

Problem solved. Thank you so much

Oct 17 '11 at 02:15 AM xDeltax
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1396
x659
x26

asked: Oct 17 '11 at 01:49 AM

Seen: 808 times

Last Updated: Oct 17 '11 at 02:18 AM