How to change already emitted particles color with gradient in a sequential formation from center to outward direction on key press?

Hi,

I have a query regarding changing gradient color of already emitted particles.
Starting color of the particle system is 40F8E9FF. I have used cone shape to achieve this form in which emission is done from Base.

[124379-1.jpg*_|124379]

I have 3 gradient colors which are predefined as shown in the photo below:

1. 40F8E9 to 8264FF 
2. FF64EB to D8EC4A 
3. 64FF78 to FF770F

[124380-2.jpg*_|124380]


Question:

  1. How can I choose a color from the gradient mentioned in the presets.
  2. How can I write a code, in which if I press a key, it pickups the color from preset, and creates an animate of color change of all particles from center to outward in a sequential progressive manner.

Till now I could use a script which helped me to change the color of all the emitted particles immediately but it is not animating.

I also tried to change m_Particles[ i +1 ].startColor, m_Particles[ i+2 ].startColor to gradiant color but my application crashed.

Please help me to solve this.


[RequireComponent(typeof(ParticleSystem))]
public class ChangeAllParticleColor : MonoBehaviour {

    ParticleSystem m_System;
    ParticleSystem.Particle[] m_Particles;
    public float m_Drift = 0.01f;

    private Color32 color;

    private void LateUpdate()
    {
        InitializeIfNeeded();

        // GetParticles is allocation free because we reuse the m_Particles buffer between updates
        int numParticlesAlive = m_System.GetParticles(m_Particles);

        // Change only the particles that are alive
        for (int i = 0; i < numParticlesAlive; i++)
        {
            //m_Particles<em>.velocity += Vector3.up * m_Drift;</em>

color = new Color(1, 1, 1);
m_Particles*.startColor = color;
_
}*_

// Apply the particle changes to the particle system
m_System.SetParticles(m_Particles, numParticlesAlive);
}

void InitializeIfNeeded()
{
if (m_System == null)
m_System = GetComponent();

if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles)
m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];
}
}
_*
_*
I am a designer but trying to write a script for animation.
Regards,
DK

Set the gradient on the ColorOverLifetime module.