- Home /
Particle system question
I'm having trouble getting the code snippet to work, any ideas? Basically this just creates a puff of smoke and when the number of particles is equal to or exceeds the min number of particles, it shuts the emitter down. At least it's supposed to. The makeSmoke function gets called from another script.
public GameObject [] smokeEmitter = new GameObject[10];
// Use this for initialization
void Start ()
{
for(int i = 0; i < 10; i++)
{
//turn off the smoke particle effect smokeEmitter[i] = GameObject.Find("Base/Missle" + (i+1) + "/Smoke");
smokeEmitter[i].particleEmitter.ClearParticles(); smokeEmitter[i].particleEmitter.emit = false; smokeEmitter[i].particleEmitter.enabled = false;
}
}
// Update is called once per frame
void Update () {
for(int i = 0; i < 10; i++) {
if((smokeEmitter[i].particleEmitter.particleCount >=
smokeEmitter[i].particleEmitter.minEmission) &&
smokeEmitter[i].particleEmitter.emit == true)
{
smokeEmitter[i].particleEmitter.ClearParticles();
smokeEmitter[i].particleEmitter.emit = false;
smokeEmitter[i].particleEmitter.enabled = false;
}
}
public void makeSmoke(index i)
{
smokeEmitter[i].particleEmitter.enabled = true;
smokeEmitter[i].particleEmitter.emit = true;
}
Please look at your posts after you post them and make sure they look readable.
Would you $$anonymous$$d letting us know what the problem is? Is the script returning an error, or is the smoke not stopping?
Oh yeah, sorry about that. Currently I'm not getting any particles to spawn.
Answer by DaveA · Feb 28, 2011 at 11:29 PM
It's going to make min particles immediately, so your code will immediately shut it down, and won't Clear and enabled=false turn off rendering too?
Try taking out the ClearParticles and enabled=false, just set emit=false, and the minimum number of particles should remain (until they fade out naturally)
You were absolutely right about the ClearParticles(), good call. Unfortunately it's still not working with just setting the particleEmitter.emit to true and false. Any ideas?
Weird thing, I put tethered the emit = true of the first object to the space bar in the update right above the check and it works perfectly??????
I just figured it out. The object that I create is scaled up from zero when its created and since this is a mesh particle emitter, the particles emit from the size of the mesh which happens to be next to nothing. Thanks everybody for helping me walk through this.
Your answer
Follow this Question
Related Questions
Particle emitter to emit "one-shot" on specific occasions 5 Answers
Particle Emitter Toggle ON/OFF 1 Answer
ParticleSystem.Play() does not play particle. 10 Answers
particle emitter when moving 1 Answer