Challenge - 5 Problems
Particle Mastery: Color and Size Over Lifetime
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Unity particle color code?
Consider this Unity C# code snippet that changes a particle's color over its lifetime. What color will the particle have at half its lifetime?
Unity
var main = particleSystem.main;
main.startColor = new ParticleSystem.MinMaxGradient(
new Gradient {
colorKeys = new GradientColorKey[] {
new GradientColorKey(Color.red, 0.0f),
new GradientColorKey(Color.blue, 1.0f)
},
alphaKeys = new GradientAlphaKey[] {
new GradientAlphaKey(1.0f, 0.0f),
new GradientAlphaKey(1.0f, 1.0f)
}
}
);
// Particle lifetime is 1 secondAttempts:
2 left
💡 Hint
Think about how gradients blend colors over time.
✗ Incorrect
The gradient blends from red at time 0 to blue at time 1. At half lifetime (0.5), the color is a mix of red and blue, which results in purple.
❓ Predict Output
intermediate2:00remaining
What size will the particle have at 75% of its lifetime?
Given this Unity C# code controlling particle size over lifetime, what is the particle size at 0.75 lifetime?
Unity
var sizeOverLifetime = particleSystem.sizeOverLifetime; sizeOverLifetime.enabled = true; sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1.0f, new AnimationCurve( new Keyframe(0.0f, 0.5f), new Keyframe(1.0f, 2.0f) ));
Attempts:
2 left
💡 Hint
The size changes linearly from 0.5 to 2.0 over the lifetime.
✗ Incorrect
At 75% lifetime, size is 0.5 + 0.75*(2.0 - 0.5) = 1.625.
🔧 Debug
advanced2:00remaining
Why does this particle color over lifetime code cause an error?
This Unity C# code snippet tries to set a particle system's color over lifetime but causes a compile error. What is the cause?
Unity
var colorOverLifetime = particleSystem.colorOverLifetime;
colorOverLifetime.enabled = true;
colorOverLifetime.color = new Gradient();
colorOverLifetime.color.colorKeys = new GradientColorKey[] {
new GradientColorKey(Color.green, 0.0f),
new GradientColorKey(Color.yellow, 1.0f)
};Attempts:
2 left
💡 Hint
Check if you can assign to colorKeys directly.
✗ Incorrect
Gradient.colorKeys is a property with only a getter. You must create a new Gradient, set its colorKeys, then assign the Gradient to a MinMaxGradient.
📝 Syntax
advanced2:00remaining
Which option correctly sets size over lifetime with a curve in Unity C#?
Choose the correct code snippet that sets a particle system's size over lifetime using an AnimationCurve.
Attempts:
2 left
💡 Hint
MinMaxCurve constructor can take a multiplier and an AnimationCurve.
✗ Incorrect
Option B correctly uses the MinMaxCurve constructor with a multiplier and an AnimationCurve. Option B is invalid because size expects a MinMaxCurve, not an AnimationCurve directly. Option B uses a wrong constructor. Option B uses two floats which is invalid.
🚀 Application
expert3:00remaining
How to create a particle system that fades color from white to transparent and grows in size over lifetime?
You want a Unity particle system where particles start white and fade to transparent, while their size grows from 0.1 to 1.0 over their lifetime. Which code snippet achieves this?
Attempts:
2 left
💡 Hint
Use GradientColorKey with Color.clear for transparency and set size with MinMaxCurve and AnimationCurve.
✗ Incorrect
Option C correctly sets the color gradient from white to transparent (Color.clear) and uses a size curve from 0.1 to 1.0. Option C uses white for both color keys, so no fade. Options B and D misuse size or color assignments.