How Play and Stop a ParticleSystem through Scripting?
Hey guys, I'm trying turn on/off a simple particle emission, when i'm using Play()/Pause() ...works fine(but particles many remains there paused), and what I want to do is when the I pause the emission, the game object stop generating particles and that particles already generated finish their cycles, like the Stop()...but when I use Play()/Stop(), the emission never starts...what should I do...? Here is my simple code: using UnityEngine; using System.Collections;
public class Test : MonoBehaviour {
public bool x;
public ParticleSystem dust;
void Start () {
}
void Update ()
{
if(x){
dust.Play();
}
else if(!x){
dust.Stop();
//dust.Pause();
//dust.Clear();
}
}
}
Answer by clunk47 · Oct 08, 2013 at 10:09 PM
Simply change ParticleSystem.enableEmission between true / false.
Answer by tw1st3d · Oct 08, 2013 at 06:33 PM
Well what you have there looks like it should work, other than the fact that you're not defining the bool as true or false anywhere, so you can try this.
public class Test : MonoBehaviour
{
protected bool letPlay = true;
public void Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
letPlay = !letPlay;
}
if(letPlay)
{
if(!gameObject.particleSystem.isPlaying)
{
gameObject.particleSystem.Play();
}
}else{
if(gameObject.particleSystem.isPlaying)
{
gameObject.particleSystem.Stop();
}
}
}
}
I tried this, i thought, that the problem was the definition...and the problem remains...
Answer by Kerihobo · Jan 29, 2015 at 02:43 AM
I had the same problem, it worked for me but it seems to only work if i first check .isplaying or !.isplaying first, and then inside that block i use .Play or .Stop
Answer by wanwanli · Feb 12, 2016 at 01:51 PM
At first I have faced the same problem, and now i have solved it! First, set Looping = true Second, set play on awake = false Finally, in your code write: void play() { ParticleSystem1.Play(); ParticleSystem1.enableEmission = true; } void stop() { ParticleSystem1.enableEmission = false; } It could work well!!!
Answer by kayding · May 16, 2016 at 02:55 PM
I just add particleSystem.enableEmission = true right after particleSystem.Play() sentence, then it's working!
Your answer
Follow this Question
Related Questions
Particle Collision between particles 2 Answers
Low particle emission rate 1 Answer
How to Instantiate decals where particles from particle system hits? 1 Answer
Particle System Help. 1 Answer