0
0
Unityframework~10 mins

Color and size over lifetime in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the particle system's start color to red.

Unity
var ps = GetComponent<ParticleSystem>();
var main = ps.main;
main.startColor = [1];
Drag options to blanks, or click blank then click option'
AColor.red
BColor.yellow
CColor.green
DColor.blue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a color other than red.
Forgetting to access the main module.
2fill in blank
medium

Complete the code to enable size over lifetime module.

Unity
var ps = GetComponent<ParticleSystem>();
var sizeOverLifetime = ps.sizeOverLifetime;
sizeOverLifetime.[1] = true;
Drag options to blanks, or click blank then click option'
AstartColor
Benabled
CstartSize
DplayOnAwake
Attempts:
3 left
💡 Hint
Common Mistakes
Using startSize which is not a property of the module.
Trying to set startColor here.
3fill in blank
hard

Fix the error in setting the color gradient for color over lifetime.

Unity
var ps = GetComponent<ParticleSystem>();
var colorOverLifetime = ps.colorOverLifetime;
colorOverLifetime.enabled = true;
colorOverLifetime.color = new ParticleSystem.MinMaxGradient([1]);
Drag options to blanks, or click blank then click option'
AColor.blue
BColor.green
CColor.red
Dnew Gradient()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a Color directly instead of a Gradient.
Not enabling the module before setting color.
4fill in blank
hard

Fill both blanks to set size over lifetime curve and enable it.

Unity
var ps = GetComponent<ParticleSystem>();
var sizeOverLifetime = ps.sizeOverLifetime;
sizeOverLifetime.[1] = new ParticleSystem.MinMaxCurve(AnimationCurve.EaseInOut(0, 0, 1, 1));
sizeOverLifetime.[2] = true;
Drag options to blanks, or click blank then click option'
Asize
Benabled
CstartSize
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using startSize which is not a property here.
Forgetting to enable the module.
5fill in blank
hard

Fill all three blanks to set a color gradient with two color keys and enable color over lifetime.

Unity
var ps = GetComponent<ParticleSystem>();
var colorOverLifetime = ps.colorOverLifetime;
var gradient = new Gradient();
gradient.colorKeys = new GradientColorKey[] {
    new GradientColorKey([1], 0.0f),
    new GradientColorKey([2], 1.0f)
};
gradient.alphaKeys = new GradientAlphaKey[] {
    new GradientAlphaKey(1.0f, 0.0f),
    new GradientAlphaKey(0.0f, 1.0f)
};
colorOverLifetime.color = new ParticleSystem.MinMaxGradient(gradient);
colorOverLifetime.[3] = true;
Drag options to blanks, or click blank then click option'
AColor.yellow
BColor.red
Cenabled
DColor.blue
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the color keys' order.
Not enabling the color over lifetime module.