private void OnParticleTrigger() { // get the particles which matched the trigger conditions this frame var numEnter = ps.GetTriggerParticles(ParticleSystemTriggerEventType.Enter, enter); if (numEnter <= 0) { return; } foreach (var item in enter) { Vector2 position = transform.position + item.position; var hit = Physics2D.OverlapPoint(position); if (hit == null) { continue; } var bloodable = hit.GetComponent <Bloodable>(); if (bloodable == null) { return; } var blood = Instantiate(bloodSplatter, position, Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f))); blood.GetComponent <SpriteRenderer>().sortingOrder = bloodable.GetComponent <SpriteRenderer>().sortingOrder + 1; blood.GetComponent <SpriteRenderer>().color = currentColor; if (bloodable.SetParent) { blood.transform.parent = (hit.transform); if (parentedBlood == null) { parentedBlood = new List <GameObject>(); } parentedBlood.Add(blood); } else { if (bloodSpatterParent == null) { bloodSpatterParent = new GameObject("BloodSpatterParent").transform; } blood.transform.parent = bloodSpatterParent; } } var particles = new ParticleSystem.Particle[ps.particleCount]; ps.GetParticles(particles); var list = particles.ToList(); foreach (var particle in enter) { list.Remove(particle); } ps.SetParticles(list.ToArray(), list.Count); }
private void MoveParticles(VaccuumSuck vacuum) { vacuum.Suck(); ParticleSystem.Particle[] particleArray = new ParticleSystem.Particle[ps.particleCount]; ps.GetParticles(particleArray); List <ParticleSystem.Particle> particleList = particleArray.ToList(); for (int i = ps.particleCount - 1; i >= 0; i--) { float strength = vacuum.GetStrength(particleList[i].position); //pts[i].position = vax.GetAxisTarget(pts[i].position); float distance = vacuum.distance(particleList[i].position); Vector3 velocity = (vacuum.GetAxisTarget(particleList[i].position) - particleList[i].position) + (vacuum.transform.position - particleList[i].position).normalized * strength * 2; ParticleSystem.Particle mod = particleList[i]; mod.velocity += velocity * strength * Time.deltaTime * 6; mod.startSize = Mathf.Lerp(mod.startSize, Mathf.Lerp(ps.main.startSize.constantMax, ps.main.startSize.constantMax * 0.1f, 1 - distance), Time.deltaTime * 6); particleList[i] = mod; if (distance < 0.1) { particleList.Remove(particleList[i]);//suck in particle vacuum.SuckIn(); } } ParticleSystem.Particle[] ptsNew = particleList.ToArray(); ps.SetParticles(ptsNew, ptsNew.Length); if (ps.particleCount == 0) { Destroy(GetComponent <Collider>()); } }