0
0
Unityframework~30 mins

Particle lifetime and speed in Unity - Mini Project: Build & Apply

Choose your learning style9 modes available
Particle lifetime and speed
📖 Scenario: You are creating a simple particle effect in Unity. Each particle has a lifetime and a speed. You want to control these properties using code.
🎯 Goal: Build a Unity script that sets up particles with specific lifetimes and speeds, then prints their properties.
📋 What You'll Learn
Create a list of particles with given lifetimes and speeds
Add a speed threshold variable
Filter particles that have speed greater than the threshold
Print the filtered particles' lifetimes and speeds
💡 Why This Matters
🌍 Real World
Controlling particle effects in games or simulations to create visual effects like fire, smoke, or magic.
💼 Career
Understanding how to manage particle properties programmatically is useful for game developers and graphics programmers.
Progress0 / 4 steps
1
Create the initial particle list
Create a list called particles that contains these exact particle data as tuples: (2.5f, 5f), (3f, 7f), (1.5f, 4f), (4f, 6f). Each tuple represents (lifetime, speed).
Unity
Need a hint?

Use List<(float, float)> and initialize with the exact tuples.

2
Add a speed threshold variable
Add a float variable called speedThreshold and set it to 5.5f inside the Start() method, below the particles list.
Unity
Need a hint?

Declare float speedThreshold = 5.5f; inside Start().

3
Filter particles by speed
Create a new list called fastParticles that contains only the particles from particles where the speed is greater than speedThreshold. Use a foreach loop with variables lifetime and speed to iterate over particles.
Unity
Need a hint?

Use a foreach loop with var (lifetime, speed) and an if to filter.

4
Print filtered particles
Use a foreach loop with variables lifetime and speed to iterate over fastParticles and print each particle's lifetime and speed in this exact format: "Particle - Lifetime: {lifetime}, Speed: {speed}" using Debug.Log.
Unity
Need a hint?

Use Debug.Log($"Particle - Lifetime: {lifetime}, Speed: {speed}") inside a foreach loop over fastParticles.