Accessing Particle Amount or Spawnduration via script?
Hey there,
is it possible to access more than just the particle time by script?
It I use the particleControlHelper and bind the particle emission to mouth open and the stoppable event to mouth closed, the Particles will all die at once - instead of finishing their lifetime ...
any trick that will get me there?
eL
So I guess there is no way to access the other particle behaviors..?
Hi El,
You can do this by transitioning the number of particles in and out before turning them off. We can do this by modifying the particleControlHelper to include a transition state.
First we need to tell our particle system that we want to control the number of particles in the scene. Select your particle material and in its Inspector panel, tick the particle count box.
Then let's modify our particleControlHelper script. At the top of the file, we can declare some variable that keeps track of our state. I also added a variable to define how fast we should change the spawnCount. Finally, we will record the spawnMaxParticles we set in the material settings so that we can transition to and from it.
Then in the update function, after we set our externalTimeInput, we will modify the number of particles we are spawning based on the state above.
Notice that we call stopParticle here after our particle count is 0, rather than when particleStopEvent is called.
Finally we'll modify how our particle system start and stop to account for the transition state. In the startParticle function, we will add
to have our particle spawn count start from 0 then letting our update function know that we should increase it.
Then we will add another function that tells our update loop to decrease the particle count when the particleStopEvent gets triggered, rather than stopping the particle instantly
In our stopParticle function we will also set the transitionState to 0 to let our update loop know that we are not transitioning.
and now you should see your particles transitioning in and out!
Let me know if you have any other questions. Can't wait to see what you come up with.
Cheers!
Jon
Our final script:
Supernice. thank you