using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SocialPlatforms; public class water : MonoBehaviour { private ParticleSystem ps; [Range(0.0f, 100f)] public int maxParticles; public float particleLife; public bool neverDies; public List<ParticleCollisionEvent> collisionEvents; void Start() { ps = GetComponent<ParticleSystem>(); collisionEvents = new List<ParticleCollisionEvent>(); } void OnParticleCollision(GameObject other) { int numCollisionEvents = ps.GetCollisionEvents(other, collisionEvents); int i = 0; while (i < numCollisionEvents) { // here i should destroy the particles hitting the gameobject i++; } } void Update() { Debug.Log("Particles Alive Count: " + GetAliveParticles()); ps.Emit(maxParticles); var main = ps.main; main.maxParticles = Mathf.RoundToInt(maxParticles); main.startLifetime = particleLife; if (neverDies) { particleLife = float.PositiveInfinity; } else { particleLife = 5f; } } int GetAliveParticles() { ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount]; return ps.GetParticles(particles); }
I didn't find any method to destroy a specific particle in the Unity Manual.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)