Search code examples
unity-game-engineparticle-system

Unity ParticleSystem collidesWith



I am trying to change collidesWith paramater of an particle system inside of a script but i am getting this error:

Error CS1612 Cannot modify the return value of 'ParticleSystem.collision' because it is not a variable


My Code:

GameObject ammo; //Game object with ParticleSystem on it
public LayerMask desiredLayers; 

private void Start()
{
    ammo.GetComponent<ParticleSystem>().collision.collidesWith = desiredLayers;
}


Now my question is what is the correct way to change the layers of a particle system collide with.


Solution

  • Okay i figure it out, apparently ParticleSystem is a property.

    And Unity have something special for ParticleSystem which uses Pointers so following code solved my problem:

    var collidesWith = ammo.GetComponent<ParticleSystem>().collision.collidesWith;
    collidesWith = desiredLayers;