How to increase value to max per second or two

Hi all,

Sorry, for stupid question, but the result of my code was confusing me. So point is that, I want to increase the amount of particles to max value during a second (or certain amount of seconds). I thought is quite easy, but I was wrong. Here is my code:

        if (particle.emissionRate <= maxValue)
        {
            particle.emissionRate += Time.deltaTime * maxValue;
        }
        particle.Key.Play();

But it is definitely is not increased to max value during one second :(. What am I doing wrong? Thanks in advance.

Not familiar with the particle creation but Time.deltaTime is a fraction of a second based on frame rate per second.

If you want to increase the particles you’ll need to set the start amount of particles and increase over time to maxValue and the increase will be by time.deltaTime / Number of seconds.

I’m assuming emissionRate is a float. Like I said not done much work with particles.

so

if (particle.emissionRate < maxValue)
{
   float curValue = particle.emissionRate;
   bool incRate = true;
   int NoOfSecs = 2;
   float difValue = maxValue - curValue;
}

if(incRate)
{
   if(patricle.emissionRate < maxValue)
   {
   particle.emissionRate = curValue + (difValue * (Time.deltaTime / NoOfSecs);
   curValue = particle.emissionRate;
   }
   else
   {
      incRate = false;
   }
}

That’s totally untested code just typed it in here but the logic seems right, as for the spelling!

Time.deltaTime is the amount of elapsed time per frame, so we would consider something like this:

if(particle.emissionRate < 1f) //Caps the emissionRate to 1
    particle.emissionRate += Time.deltaTime; //Adds a frame to the emissionRate.

Now let’s add the maximum emissionRate and the number of seconds to do so… We’ll assume that maxValue is 10 and numSeconds is 2, making this increase emissionRate to 10 in two seconds.

float maxValue = 10f;
float numSeconds = 2f;

if(particle.emissionRate < maxValue)
    particle.emissionRate += (Time.deltaTime/numSeconds) * maxValue;