CodeBlanks Logo Icon CodeBlanks

Color over lifetime

Learn particle color with Color over Lifetime.

Color over Lifetime Module

Particles do not need to remain a static color throughout their lifespan. The Color over Lifetime module controls how a particle's color and transparency (alpha) evolve from birth to death. This allows flame particles to transition from yellow to red, and finally into grey smoke.

var col = ps.colorOverLifetime;
col.enabled = true;

Color and Transparency Transitions with Gradient

Color transition is defined using a Gradient structure. Gradients contain color keys and alpha keys. For instance, configuring a particle to spawn fully visible (alpha = 1) and fade away gently upon death (alpha = 0) is achieved through these keys.

// Color and transparency change over time in Gradient:
// Start: White, End: Transparent

Practice Enable Color Module

Set col.enabled to true and print it with Debug.Log("Renk modulu: " + col.enabled);.

Starter code

Player.cs
using System;

public class ColorOverLifetimeModule
{
    public bool enabled = false;
}

public static class Debug
{
    public static void Log(object message) => Console.WriteLine(message);
}

public class Program
{
    public static void Main()
    {
        ColorOverLifetimeModule col = new ColorOverLifetimeModule();
        // Modulu etkinlestir ve durumunu yazdir
    }
}

Sample solution

Player.cs
using System;

public class ColorOverLifetimeModule
{
    public bool enabled = false;
}

public static class Debug
{
    public static void Log(object message) => Console.WriteLine(message);
}

public class Program
{
    public static void Main()
    {
        ColorOverLifetimeModule col = new ColorOverLifetimeModule();
        col.enabled = true;
        Debug.Log("Renk modulu: " + col.enabled);
    }
}

Expected output

Renk modulu: True

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which module allows a particle's color and transparency to transition gradually from birth to death?

  • Collision
  • Color over Lifetime Correct answer
  • Size over Lifetime
  • Velocity over Lifetime

Explanation: The Color over Lifetime module changes the particle's color and transparency across its lifetime using a gradient.

2 Select Module

Question
var renkModulu = ps.____;
Answer
var renkModulu = ps.colorOverLifetime;

Explanation: The module controlling color transition over lifetime is colorOverLifetime.

3 Color Module Concepts

Term Meaning
Color over Lifetime Color and alpha change over lifetime
Gradient Smooth transition scale between colors
Alpha Key Transparency stop at a point
Color Key Hue stop at a specific point

All lessons in Intermediate