Search Unity

Kill or change parameter of particle with collision

Discussion in 'Scripting' started by Mazdamundi, May 2, 2020.

  1. Mazdamundi

    Mazdamundi

    Joined:
    Dec 5, 2017
    Posts:
    9
    Hi Everyone !

    I would like to modify the particle's attributs who enter in collision with my object. Not all particles, only those who enter in collision.

    I wrote this but this work for ALL the particles, not only the one who enter in collision
    (The aim is to kill them but for this script I just tried to change the color)

    Code (CSharp):
    1. void OnParticleCollision(GameObject other)
    2.     {
    3.         ParticleSystem.Particle[] particlelist = new ParticleSystem.Particle[Meteorite.particleCount];
    4.  
    5.         int test = Meteorite.GetParticles(particlelist);
    6.  
    7.    
    8.         for (int i = 0; i < test; i++)
    9.         {
    10.             if (Atmosphere.color.a > 0.5f)
    11.             {
    12.                 particlelist[i].color = Color.red;
    13.             }
    14.         }
    15.         Meteorite.SetParticles(particlelist, test);
    16.    
    17.  
    18.     }
    If someone can help me that's will be great !!

    Thanks :)
     
    Last edited: May 2, 2020