Legacy Documentation: Version 5.6 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MinMaxGradient

struct in UnityEngine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

MinMaxGradient contains two Gradients, and returns a Color based on ParticleSystem.MinMaxGradient.mode. Depending on the mode, the Color returned may be randomized. Gradients are edited via the ParticleSystem Inspector once a ParticleSystemGradientMode requiring them has been selected. Some modes do not require gradients, only colors.

See Also: ParticleSystem.

#pragma strict
// This example shows setting a constant color value.
public class ConstantColorExample extends MonoBehaviour {
	var myParticleSystem: ParticleSystem;
	var colorModule: ParticleSystem.ColorOverLifetimeModule;
	function Start() {
		// Get the system and the color module.
		myParticleSystem = GetComponent.<ParticleSystem>();
		colorModule = myParticleSystem.colorOverLifetime;
		GetValue();
		SetValue();
	}
	function GetValue() {
		print("The constant color is " + colorModule.color.color);
	}
	function SetValue() {
		colorModule.color = Color.red;
	}
}
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; } }
#pragma strict
// This example shows using 2 colors to drive the color over lifetime.
public class TwoConstantColorsExample extends MonoBehaviour {
	var myParticleSystem: ParticleSystem;
	var colorModule: ParticleSystem.ColorOverLifetimeModule;
	function Start() {
		// Get the system and the color module.
		myParticleSystem = GetComponent.<ParticleSystem>();
		colorModule = myParticleSystem.colorOverLifetime;
		GetValue();
		SetValue();
	}
	function GetValue() {
		print(String.Format("The constant values are: min {0} max {1}.", colorModule.color.colorMin, colorModule.color.colorMax));
	}
	function SetValue() {
		colorModule.color = new ParticleSystem.MinMaxGradient(Color.green, Color.red);
	}
}
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); } }
#pragma strict
// This example shows using a gradient to drive the color over lifetime.
public class GradientColorExample extends MonoBehaviour {
	var myParticleSystem: ParticleSystem;
	var colorModule: ParticleSystem.ColorOverLifetimeModule;
	var ourGradient: Gradient;
	function 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.
		var alpha: float = 1.0f;
		ourGradient = new Gradient();
		ourGradient.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [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);
	}
	function ModifyGradient() {
		// Reduce the alpha
		var alpha: float = 0.5f;
		ourGradient.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f)]);
		// Apply the changed gradient.
		colorModule.color = ourGradient;
	}
}
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; } }
#pragma strict
// This example shows using 2 gradients to drive the color over lifetime.
public class TwoGradientColorExample extends MonoBehaviour {
	var myParticleSystem: ParticleSystem;
	var colorModule: ParticleSystem.ColorOverLifetimeModule;
	var ourGradientMin: Gradient;
	var ourGradientMax: Gradient;
	function 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.
		var alpha1: float = 1.0f;
		ourGradientMin = new Gradient();
		ourGradientMin.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [new GradientAlphaKey(alpha1, 0.0f), new GradientAlphaKey(alpha1, 1.0f)]);
		// A simple 2 color gradient with a fixed alpha of 0.0f.
		var alpha2: float = 0.0f;
		ourGradientMax = new Gradient();
		ourGradientMax.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [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);
	}
	function ModifyGradient() {
		// Reduce the alpha
		var alpha: float = 0.5f;
		ourGradientMin.SetKeys([new GradientColorKey(Color.green, 0.0f), new GradientColorKey(Color.red, 1.0f)], [new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f)]);
		// Apply the changed gradients.
		colorModule.color = new ParticleSystem.MinMaxGradient(ourGradientMin, ourGradientMax);
	}
}
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); } }

Variables

colorSet a constant color.
colorMaxSet a constant color for the upper bound.
colorMinSet a constant color for the lower bound.
gradientSet the gradient.
gradientMaxSet a gradient for the upper bound.
gradientMinSet a gradient for the lower bound.
modeSet the mode that the min-max gradient will use to evaluate colors.

Constructors

ParticleSystem.MinMaxGradientA single constant color for the entire gradient.

Public Functions

EvaluateManually query the gradient to calculate colors based on what mode it is in.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961