Hi,
I want to destroy the particles which, when the emitter moves around particles float off into the distance.
This is what ive got so far but it dont work correctly (c#)
void OnTriggerExit(Collider col)
{
UnityEngine.Object.Destroy(col.collider);
}
you could also just use the trigger event in the particle system and have them killed if they leave a volume
I did something similar by destroying particles that are a certain distance from the emitter:
using System.Linq;
/// <summary>
/// Destroys particles that are farther than DistanceToDestroy from the particlesystem emitter
/// </summary>
[RequireComponent(typeof(ParticleSystem))]
public class ParticleMaxDistance : MonoBehaviour
{
public float DistanceToDestroy;
private ParticleSystem cachedSystem;
private Vector3 staticPosition;
void Start()
{
cachedSystem = this.GetComponent<ParticleSystem>();
staticPosition = this.transform.position;
}
void Update()
{
ParticleSystem.Particle[] ps = new ParticleSystem.Particle[cachedSystem.particleCount];
cachedSystem.GetParticles(ps);
// keep only particles that are within DistanceToDestroy
var distanceParticles = ps.Where(p => Vector3.Distance(staticPosition, p.position) < DistanceToDestroy).ToArray();
cachedSystem.SetParticles(distanceParticles, distanceParticles.Length);
}
}