Modify a Particle System with C#

Trying to modify a particle system via C# script. There is lots of documentation about it yet I keep getting errors.

I am using 5.4x.

The code I have found makes reference to “main” and yet when I run that code I get an error that UnityEngine.ParticleSystem has no definition for “main” so I presuming that “main” has been deprecated.

So could someone post a simple example of code that I would attach to a particle system that would modify particle duration as well as emission rate? I should be able to adapt it from there.

It’s not deprecated, it’s new. If you are using an old version of unity, you will need to look at the docs for that version

Added with Unity 5.5.

Thank you. And just to close the loop on this for future searchers, here is my final code:

public ParticleSystem particleLauncher;

void Update ()
{
ParticleSystem.MainModule psMain = particleLauncher.main;
ParticleSystem.ShapeModule psShape = particleLauncher.shape;
psShape.radius = 1;
psMain.startLifetime = 1.0f;
psMain.startSpeed = 30;
particleLauncher.Emit (1);
}

The various constants would be replaced with variables if you wish things to change over time.

8 Likes