- Home /
Shuriken particle system : disable and re-enable emitter
Hello everyone,
I am currently stuck using the particle system on Unity 3.5
My character is able to switch between 2 weapons, by throwing them out of the screen. These weapons have a particlesystem attached to them.
What I want is to stop emitting when the weapon isn't used. It seems easy, but using
Stop();
or
enableEmission=false;
are making the particles already emitted disappear. I could work with that, but it's not as pretty as it could be.
Worse, when I get the disabled weapon back, using
Play();
or
enableEmission=true;
make those disappeared particles reappear at the exact point they were when I disabled the emission.
All I can do is use
Clear();
To remove those invisible, unsimulated particles. But they still disappear strangely.
I would like to know if there is a way to :
Disable emission without deleting the particles.
Reenable emission from the beginning (Simulate(0f) doesn't work).
Thanks.
Answer by AeonIxion · Nov 28, 2012 at 09:29 AM
Perhaps you can use particleSystem.Emit(int count) in the update function?
I COULD do the emission myself, and so might be able to change this annoying Stop() behaviour ! I'll mark as correct if this works, thanks.
Thanks a lot. Now, I just have to find a way to simulate the "distance" emission, and disable my weapon's renderer. That's too bad something as simple as this needs manual tweaking, even this $$anonymous$$imal.
Answer by Tea_Doogun · Nov 27, 2012 at 05:48 PM
Shuriken is a little different to the old particle system...this is how i did it:
Start by making a variable:
var beam : ParticleSystem;
function Start(){
//this will make the particle system usable in function Update
beam = GetComponent(ParticleSystem);
//this clears the particle system when you start the game...use it if you like
beam.Stop();
beam.Clear();
}
function Update(){
//This will start the particles playing when you press the left mouse button
if (Input.GetMouseButton(0)){
beam.Play();
}
//This will stop the particle system when you let go of the button
if (Input.GetMouseButtonUp(0)){
beam.Stop();
beam.Clear();
}
}
Attach the script to the particle system, and drag the same particle system into the 'beam' variable.
Hopefully this gives you an idea of how the particle system can be stopped and started
If you have 2 particle systems, just use 2 variables (beam & beam2 for instance)
Not used to answering questions, let me know if anything is unclear :)
edited, i didn't use an empty game object, i just put the script onto the particle system itself.
Hello. First, thanks for your answer. second, This is also the solution I have so far. the problem being that "stop" also deletes the particules that have already been emitted.
Oh, whoops. Like i say, not used to answering questions :p
The only other thing that comes to $$anonymous$$d is increasing the 'Start Lifetime' in the particle system. Other than that, i'm stuck.
Sorry man.
No problem, at least you tried. I'll check that, thanks.
Hey guys, if I may ask, how do you declare "beam" in c#?
ParticleSystem beam = GetComponent(ParticleSystem);
so beam is simply the shuriken particle system you added to your game object. Same game object that contains this script.