- Home /
execute function only for the justborn particles using C#??
Hi,
I am trying to run some functions only to the "just born" particles. Below is my trial but do I have any better ways?
ParticleSystem.Particle[] ps = new ParticleSystem.Particle[sys.maxParticles];
int count = sys.GetParticles(ps);
for (int i = 0; i < count; i++)
{
if (ps[i].remainingLifetime < ps[i].startLifetime * 0.99f)
{
some functions
}
}
thanks!
Answer by Naphier · Oct 20, 2016 at 03:39 AM
I'd do if(ps[i].startLifeTime - ps[i].lifeTime < Time.deltaTime) Then you're only checking (hopefully) what was created in the last frame. There doesn't appear to be any callback to see if a single particle was emitted (probably too much risk of overhead).
What are you trying to accomplish? There may be a better way.
Answer by marchall_box · Oct 21, 2016 at 07:27 AM
I am sample a texture with position and emitting particle from the position. So I need to have the color to be applied when it is born.
I ended up actually Emitting particle from script so it has the color in ParticleParam. I guess it works for now.
Interesting, you might also be able to put the particles that have changed color into a List so that you can check against it. But if there are a lot of particles and you don't flush the list, then that may end up being more overhead than checking if the particle has been alive for less than X seconds.