Particle System does not start when lid is open
I have an animation created for a treasure chest that opens and closes the lid depending on a boolean response. The chest consists of two pieces and is configured with a generic rig. The animation simply rotates the lid on the X axis -90 degrees to open.
The problem is I wrote a script to start a particle system (which is attached to an empty game object called 'Radiance') that should start when the lid's x position is less then -25 degrees. The chest opens and closes fine but the particle system never starts. Here is my script attached to the lid-
using UnityEngine;
public class treasure_chest_glow : MonoBehaviour
{
public ParticleSystem radiate;
private void Awake()
{
radiate = GetComponent<ParticleSystem>();
}
private void LateUpdate()
{
if (transform.rotation.x < -25) radiate.Play();
else
{
radiate.Stop();
}
}
}
Any help would be appreciated!
Answer by ifurkend · Feb 03, 2019 at 08:49 AM
The issue here is that Play() is more accurately a "replay/restart" method. That means once your chest is opened, your script is resetting the effect every single frame. Instead you should switch the Particle System Emission module like this, assuming your effect is constantly looping:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayParticleSystem : MonoBehaviour {
public ParticleSystem ps;
private ParticleSystem.EmissionModule psm_emission;
public bool _play = false;
void Awake () {
ps = GetComponent<ParticleSystem>();
psm_emission = ps.emission;
psm_emission.enabled = false;
ps.Play();
}
void Update () {
if (_play) {
psm_emission.enabled = true;
} else {
psm_emission.enabled = false;
}
}
}
Answer by tsabra76 · Feb 05, 2019 at 05:49 PM
I never considered it being reset every frame, I really appreciate your feedback!
Your answer
