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();
}
}
}
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 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
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!!!
What a pain in the butt. Here’s a simple script that would turn on/off your Particle Effect when you hit the “H” button:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParticleTest : MonoBehaviour {
public GameObject myParticles;
void Start(){
myParticles.SetActive (false);
}
void Update(){
if (Input.GetKeyDown ("h") && myParticles.activeSelf == false) {
myParticles.SetActive (true);
} else if (Input.GetKeyDown ("h") && myParticles.activeSelf == true) {
myParticles.SetActive (false);
}
}
This is attached to my Player, then you drag the ParticleSystem prefab you want to use in for your GameObject.
Make sure your ParticleSystem is set to PlayOnAwake* = true. This killed me for the longest time… we set a static reference and turn it on off first… then on and off from there.
Looping is whether you want it to fire once, or keep firing until you turn it off. This example is a campfire that turns on (Looping = true), and then turns back off when you hit the button again.
There’s probably a better way, but good luck finding it. Everything I’ve tried to use from Unity Manual & tutorials on using ParticleSystems doesn’t ever work for me.
In Unity3D editor 2020.3 and later (maybe before, dont know) the “particleSystem.enableEmission” is obsolete.
Use “ParticleSystem.EmissionModule.enabled”