# ParticleSystem.MinMaxGradient

> Script interface for a Min-Max Gradient.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.ParticleSystemModule

```csharp
public struct ParticleSystem.MinMaxGradient
```

## Remarks

This contains two [Gradient](/engine/6000.0/script-reference/unityengine/gradient.md)s, and returns a [Color](/engine/6000.0/script-reference/unityengine/color.md) based on [ParticleSystem.MinMaxGradient.mode](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/mode.md). Depending on the mode, this may return the value randomized. Gradients are edited via the ParticleSystem Inspector once a [ParticleSystemGradientMode](/engine/6000.0/script-reference/unityengine/particlesystemgradientmode.md) requiring them has been selected. Some modes do not require gradients, only colors. Additional Resources: [ParticleSystem](/engine/6000.0/script-reference/unityengine/particlesystem.md).

## Examples

```csharp
using UnityEngine;

// This example shows setting a constant color value.
public class ConstantColorExample : MonoBehaviour
{
    ParticleSystem myParticleSystem;
    ParticleSystem.ColorOverLifetimeModule colorModule;

    void Start()
    {
        // Get the system and the color module.
        myParticleSystem = GetComponent<ParticleSystem>();
        colorModule = myParticleSystem.colorOverLifetime;

        GetValue();
        SetValue();
    }

    void GetValue()
    {
        print("The constant color is " + colorModule.color.color);
    }

    void SetValue()
    {
        colorModule.color = Color.red;
    }
}
```

```csharp
using UnityEngine;

// This example shows using 2 colors to drive the color over lifetime.
public class TwoConstantColorsExample : MonoBehaviour
{
    ParticleSystem myParticleSystem;
    ParticleSystem.ColorOverLifetimeModule colorModule;

    void Start()
    {
        // Get the system and the color module.
        myParticleSystem = GetComponent<ParticleSystem>();
        colorModule = myParticleSystem.colorOverLifetime;

        GetValue();
        SetValue();
    }

    void GetValue()
    {
        print(string.Format("The constant values are: min {0} max {1}.", colorModule.color.colorMin, colorModule.color.colorMax));
    }

    void SetValue()
    {
        colorModule.color = new ParticleSystem.MinMaxGradient(Color.green, Color.red);
    }
}
```

```csharp
using UnityEngine;

// This example shows using a gradient to drive the color over lifetime.
public class GradientColorExample : MonoBehaviour
{
    ParticleSystem myParticleSystem;
    ParticleSystem.ColorOverLifetimeModule colorModule;
    Gradient ourGradient;

    void Start()
    {
        // Get the system and the color module.
        myParticleSystem = GetComponent<ParticleSystem>();
        colorModule = myParticleSystem.colorOverLifetime;

        // A simple 2 color gradient with a fixed alpha of 1.0f.
        float alpha = 1.0f;
        ourGradient = new Gradient();
        ourGradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
        );

        // Apply the gradient.
        colorModule.color = ourGradient;

        // In 5 seconds we will modify the gradient.
        Invoke("ModifyGradient", 5.0f);
    }

    void ModifyGradient()
    {
        // Reduce the alpha
        float alpha = 0.5f;
        ourGradient.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
        );

        // Apply the changed gradient.
        colorModule.color = ourGradient;
    }
}
```

```csharp
using UnityEngine;

// This example shows using 2 gradients to drive the color over lifetime.
public class TwoGradientColorExample : MonoBehaviour
{
    ParticleSystem myParticleSystem;
    ParticleSystem.ColorOverLifetimeModule colorModule;

    Gradient ourGradientMin;
    Gradient ourGradientMax;

    void Start()
    {
        // Get the system and the emission module.
        myParticleSystem = GetComponent<ParticleSystem>();
        colorModule = myParticleSystem.colorOverLifetime;

        // A simple 2 color gradient with a fixed alpha of 1.0f.
        float alpha1 = 1.0f;
        ourGradientMin = new Gradient();
        ourGradientMin.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha1, 0.0f), new GradientAlphaKey(alpha1, 1.0f) }
        );

        // A simple 2 color gradient with a fixed alpha of 0.0f.
        float alpha2 = 0.0f;
        ourGradientMax = new Gradient();
        ourGradientMax.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha2, 0.0f), new GradientAlphaKey(alpha2, 1.0f) }
        );

        // Apply the gradients.
        colorModule.color = new ParticleSystem.MinMaxGradient(ourGradientMin, ourGradientMax);

        // In 5 seconds we will modify the gradient.
        Invoke("ModifyGradient", 5.0f);
    }

    void ModifyGradient()
    {
        // Reduce the alpha
        float alpha = 0.5f;
        ourGradientMin.SetKeys(
            new GradientColorKey[] { new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f) },
            new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
        );

        // Apply the changed gradients.
        colorModule.color = new ParticleSystem.MinMaxGradient(ourGradientMin, ourGradientMax);
    }
}
```

```csharp
using UnityEngine;

// This example shows how to retrieve existing color and alpha keys from a MinMaxGradient
public class ReadGradientExample : MonoBehaviour
{
    void Start()
    {
        // Get the system and the color module.
        var myParticleSystem = GetComponent<ParticleSystem>();
        var colorModule = myParticleSystem.colorOverLifetime;

        // Get the gradient (assuming the MinMaxGradient is in Gradient mode)
        Gradient gradient = colorModule.color.gradient;

        // Get the keys
        GradientColorKey[] colorKeys = gradient.colorKeys;
        GradientAlphaKey[] alphaKeys = gradient.alphaKeys;
    }
}
```

## Constructors

| Constructor                                                                                                                                                                        | Description                                                                             |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| [MinMaxGradient(UnityEngine.Color)](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/ctor.md#minmaxgradient\(color\))                                     | A single constant color for the entire gradient.                                        |
| [MinMaxGradient(UnityEngine.Color,UnityEngine.Color)](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/ctor.md#minmaxgradient\(color-color\))             | Randomly select colors based on the interval between the minimum and maximum constants. |
| [MinMaxGradient(UnityEngine.Gradient)](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/ctor.md#minmaxgradient\(gradient\))                               | Use one gradient when evaluating numbers along this Min-Max Gradient.                   |
| [MinMaxGradient(UnityEngine.Gradient,UnityEngine.Gradient)](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/ctor.md#minmaxgradient\(gradient-gradient\)) | Randomly select colors based on the interval between the minimum and maximum gradients. |

## Properties

| Property                                                                                                | Description                                                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| [color](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/color.md)             | Set a constant color.                                           |
| [colorMax](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/colormax.md)       | Set a constant color for the upper bound.                       |
| [colorMin](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/colormin.md)       | Set a constant color for the lower bound.                       |
| [gradient](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/gradient.md)       | Set the gradient.                                               |
| [gradientMax](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/gradientmax.md) | Set a gradient for the upper bound.                             |
| [gradientMin](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/gradientmin.md) | Set a gradient for the lower bound.                             |
| [mode](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/mode.md)               | Set the mode that the Min-Max Gradient uses to evaluate colors. |

## Methods

| Method                                                                                            | Description                                                                  |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [Evaluate](/engine/6000.0/script-reference/unityengine/particlesystem/minmaxgradient/evaluate.md) | Manually query the gradient to calculate colors based on what mode it is in. |
