0
0
Unityframework~30 mins

Color and size over lifetime in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Color and size over lifetime
📖 Scenario: You are creating a simple particle effect in Unity. Each particle changes its color and size as it lives. This makes the effect look more natural and interesting.
🎯 Goal: Build a Unity script that changes a particle's color and size smoothly over its lifetime.
📋 What You'll Learn
Create a Unity script with a ParticleSystem component reference
Define color and size gradients over the particle lifetime
Apply these gradients to the particle system's main module
Print confirmation that the setup is complete
💡 Why This Matters
🌍 Real World
Particle effects like fire, smoke, or magic spells often change color and size over their lifetime to look realistic.
💼 Career
Game developers and interactive media creators use these techniques to make engaging visual effects.
Progress0 / 4 steps
1
Set up the ParticleSystem reference
Create a public variable called particleSystem of type ParticleSystem inside a new C# class called ColorSizeOverLifetime.
Unity
Need a hint?

Use public ParticleSystem particleSystem; inside the class.

2
Create color and size gradients
Inside the ColorSizeOverLifetime class, create two public variables: colorGradient of type Gradient and sizeCurve of type AnimationCurve.
Unity
Need a hint?

Use public Gradient colorGradient; and public AnimationCurve sizeCurve;.

3
Apply color and size over lifetime
In the Start() method, get the colorOverLifetime and sizeOverLifetime modules from particleSystem. Set colorOverLifetime.color to colorGradient and sizeOverLifetime.size to sizeCurve.
Unity
Need a hint?

Use particleSystem.colorOverLifetime and particleSystem.sizeOverLifetime modules and enable them.

4
Print confirmation message
Add a Debug.Log statement inside Start() that prints "Color and size over lifetime set!".
Unity
Need a hint?

Use Debug.Log("Color and size over lifetime set!"); inside Start().