using UnityEngine;

public class ChangeParticleColour : MonoBehaviour
{
    //for this to work, make sure that ColorOverLifetime is disabled.
    //this script only changes the StartColour parameter, which would be overwritten by ColorOverLifetime.

    ParticleSystem.MainModule mains;

    void Start()
    {
        mains = GetComponent<ParticleSystem>().main;
    }

    // Update is called once per frame
    void Update()
    {
        //TEST
        //Color newColor = new Color(0f, 0f, 1f, 1f);
        //Color newColor3 = new Color(0f, 1f, 1f, 1f);
        //setColors(newColor, newColor3, 0.5f);
    }


    public void setColors(Color c1, Color c2, float alpha)
    {
        Gradient gradient = new Gradient();

        GradientColorKey[] gradientColors = new GradientColorKey[2];
        gradientColors[0].color = c1;
        gradientColors[1].color = c2;
        gradientColors[0].time = 0f;
        gradientColors[1].time = 1f;

        GradientAlphaKey[] gradientAlpha = new GradientAlphaKey[2];
        gradientAlpha[0].alpha = 1;
        gradientAlpha[0].time = 0;
        gradientAlpha[1].alpha = alpha;
        gradientAlpha[1].time = 0.5f;

        gradient.SetKeys(gradientColors, gradientAlpha);

        mains.startColor = new ParticleSystem.MinMaxGradient(gradient);
    }
}
