Particle Effect to disable after it's played once
I've been trying to get this particle effect attached to a 2D object to play when the object is destroyed or hit by another object and then disappear after it's played once, I've managed to get it to play with the collision, however it won't stop playing after the object is destroyed. The particle effect is attached to the game object as a child, and I have it running over several scripts, a spawner script and the particle effect script. The Game object has the particle effect script attached with the particle effect attached to that, along with the spawner script attached to the game object with the particle effect attached to that. I've unticked looping on the particle effect and I have run out of ideas. If anyone is able to help out I would greatly appreciate it.
Spawner Script
public GameObject prefabToSpawn;
public float adjustmentAngle = 0.0f;
public void Spawn()
{
Vector3 rotationinDegrees = transform.eulerAngles;
rotationinDegrees.z += adjustmentAngle;
Quaternion rotationInRadians = Quaternion.Euler(rotationinDegrees);
Instantiate(prefabToSpawn, transform.position, rotationInRadians);
}
Particle Effect Script
public ParticleSystem Explosion;
void Start()
{
//Disables the particle effect
Explosion.GetComponent<ParticleSystem>().enableEmission = false;
}
private void OnTriggerEnter2D(Collider2D collision)
{
// When the collision has been recognised plays particle effect
Explosion.GetComponent<ParticleSystem>().enableEmission = true;
Explosion.GetComponent<ParticleSystem>().Play();
StartCoroutine(StopExplosion());
}
IEnumerator StopExplosion()
{
// Stops particle effect
yield return new WaitForSeconds(.1f);
Explosion.GetComponent<ParticleSystem>().enableEmission = false;
}
Uncheck “looping” in the particle system, including all child particle systems, set proper duration if it’s too short or too long.
Have you figured this out? I am working on a similar issue.
Answer by Madchazzer · May 05, 2019 at 11:30 AM
@bubsoxs sorry but apparently the only thing wrong I had was what @ifurkend pointed out, the looping check box, which I thought I had already unchecked. Sorry I couldn't be any more help. Sorry I didn't say thanks sooner ifurkend, so thanks.
I'm getting enableemission = false is showing obsolete error. I'm using unity 2018 for this project. Also do I need to turn off emissions and turn off start awake in the inspector? I have fireball particle effect that when collides with a target it will trigger the explosion particle effect using ontriggerenter2d. I am using boxcollider2d. The explosion effect is a child of the fireball. I am relatively new to unity so any suggestions would be great. I been searching this topic for a few days now and I am stuck...
Unity has long changed the way to script with Particle System:
https://blogs.unity3d.com/2016/04/20/particle-system-modules-faq/
In short, if you're merely reading the value, you can simply do this:
float _rateOverTime = _particleSystem.emission.rateOverTime$$anonymous$$ultiplier;
But if you're to change the value, you must cache the module class of the target value to a variable first:
var _psm_emission = _particleSystem.emission;
_psm_emission.rateOverTime$$anonymous$$ultiplier = _someFloatValue;
Your answer
Follow this Question
Related Questions
Particles Instantiate doesnt show up (Hidden behind background image) 0 Answers
How to make Particle System on when I throw grenades on ground after 5 second. 3 Answers
Sub emitters: Start Delay & Burst Cycles do not work 0 Answers
Problem with Particles and Particle System 1 Answer
How can you create non circular rocket flame particle effect? 0 Answers