Absinthe
Absinthe

Reputation: 3391

Get particle gradient color

I see how to set a particle's color based on a gradient (e.g. this & this) but I can't find anything on how to get the color.

I have a particle system with the start color set to random with a gradient. I've tried...

Color myColor = myParticleSystem.main.startColor.color

... but it always returns black, regardless of the gradient colors.

I don't see anything in the docs or forums about how to actually get the color that was randomly chosen.

Using Unity 2017.3. Thanks.

Upvotes: 0

Views: 667

Answers (1)

Galandil
Galandil

Reputation: 4249

At the moment, we can't read the MinMaxCurve from scripts, as per here: https://blogs.unity3d.com/2016/04/20/particle-system-modules-faq/ (scroll down to the Easing the Pain section).

However, your code returns not a MinMaxCurve, but the Start Color of type Color that you can set via inspector or via script.

For example, if you create a Particle System game object in a scene, and you attach to it this simple script:

using UnityEngine;

public class ParticlesTest : MonoBehaviour {

    ParticleSystem myParticleSystem;
    public Color myColor;

    private void Awake() {
        myParticleSystem = GetComponent<ParticleSystem>();      
    }

    private void Update() {
        myColor = myParticleSystem.main.startColor.color;
    }
}

you can see that myColor changes when you change the Start Color value of the Particle System in Play mode.

Upvotes: 2

Related Questions