- Home /
Particle emitter to emit "one-shot" on specific occasions
Hi. Question is simple... I have a cannon... when it goes boom, particles are emmited once... once it goes boom again, particles are emmited once... so on... Problem is, when it goes boom for the first time, i turn the emitter on, and even thou I have "one shot" selected, it keeps emmiting particles.. Is there a "correct" way to solve it? I`ve read stuff about creating co-routines and stuff... no other way? thks.
Answer by Eric5h5 · Feb 09, 2011 at 04:22 AM
"One-shot" doesn't mean the particles are emitted only one time, it means the particles are emitted all at once instead of over time. When all the particles run out of energy, they are emitted again, and will continue as long as the particle system is active and emit is set to true. What you're probably looking for is particleEmitter.Emit()
(particleEmitter.emit
should be false).
This is the perfect, and simple solution to one shot/one play particles.
Thanks for this! manually emitting a single particle was extremely useful for my project.
Answer by lampshade · Feb 09, 2011 at 04:15 AM
Are there any scripts attached to this cannon you speak of?
public class Cannon : MonoBehaviour {
public static bool turnOnEmitter = false;
private void Update() { BoomScript(); }
private void BoomScript() {
ParticleEmitter pEmitter = GetComponent<ParticleEmitter>( );
if (turnOnEmitter) {pEmitter.emit = true;}
else
pEmitter.emit = false;
} }
$$anonymous$$ake sure AutoDestruct is off as well as One Shot, and toggle turnOnEmitter as needed in the inspector (For Testing) and then you could reference turnOnEmitter statically in another script.
This is pretty cumbersome; you can just use Emit() ins$$anonymous$$d.
Answer by chozabu · Oct 21, 2011 at 03:14 AM
My solution to this problem was to create a prefab of a particle system; tick one-shot in the emitter and autodestruct on the animator. I then create an instance of that prefab when I want the smoke. Before this I was trying to do a method like the other answers here - but was landlocked by yield not working! It would just never return... (in boo, not tried other langs recently)
Answer by efge · Dec 24, 2012 at 02:36 PM
My solution:
chozabu's solution: "Create a prefab of a particle system; tick one-shot in the emitter and autodestruct on the animator. I then create an instance of that prefab when I want the smoke."
plus
Set Min Energy in the emitter to Zero.
Answer by shadowpuppet · Dec 19, 2016 at 01:28 AM
I used one of the supplied emitters prefabs. "sparks". I edited it to look like blood splatter then had the same problem discussed here. I opened the animation window and did 2 animations . the first the emitter is on and goes off after 1.5 seconds. The second animation is just dead 10 frames with the emitter off. In the animator window I have NewState as the default that transitions to my first animation on exit time ( which is immediate) and that - on exit time transitions to my second dead animation and there it just loops invisibly. So each time I shoot flesh and the blood splatter instantiates it plays those the first animation transitioning to the second animation where it remains off until the prefab times out
Your answer
Follow this Question
Related Questions
Particle emitter works intermittently 0 Answers
Particle Emitter Toggle ON/OFF 1 Answer
Can you make a particle emitter that emits inwards? 4 Answers
Particle emitter object destroys itself 2 Answers