0
0
Unityframework~10 mins

Particle collision 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 detect when a particle collides with another object.

Unity
void OnParticleCollision(GameObject [1]) {
    Debug.Log("Particle collided with " + [1].name);
}
Drag options to blanks, or click blank then click option'
Aother
Bcollider
Ccollision
Dobj
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that doesn't match the method signature.
Confusing the parameter type with collision data.
2fill in blank
medium

Complete the code to get the ParticleSystem component attached to the GameObject.

Unity
ParticleSystem ps = gameObject.[1]<ParticleSystem>();
Drag options to blanks, or click blank then click option'
AFindObjectOfType
BGetComponent
CAddComponent
DGetComponents
Attempts:
3 left
💡 Hint
Common Mistakes
Using AddComponent instead of GetComponent.
Using FindObjectOfType which searches the whole scene.
3fill in blank
hard

Fix the error in the code to correctly stop the particle system on collision.

Unity
void OnParticleCollision(GameObject other) {
    ParticleSystem ps = other.GetComponent<ParticleSystem>();
    if (ps != null) {
        ps.[1]();
    }
}
Drag options to blanks, or click blank then click option'
APause
BPlay
CDestroy
DStop
Attempts:
3 left
💡 Hint
Common Mistakes
Using Play() which starts the system instead of stopping it.
Using Destroy() which removes the component instead of stopping it.
4fill in blank
hard

Fill both blanks to check if the collided object has a specific tag and then stop its particle system.

Unity
void OnParticleCollision(GameObject [1]) {
    if ([1].CompareTag("Enemy")) {
        ParticleSystem ps = [1].GetComponent<ParticleSystem>();
        if (ps != null) {
            ps.Stop();
        }
    }
}
Drag options to blanks, or click blank then click option'
Aother
Bobj
Ctarget
Dcollider
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors.
Using a variable name not declared as parameter.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps particle system names to their collision counts, only including those with counts greater than zero.

Unity
Dictionary<string, int> collisionCounts = new Dictionary<string, int>();
foreach (var ps in particleSystems) {
    int count = ps.GetCollisionEvents(gameObject, collisionEvents);
    if (count [1] 0) {
        collisionCounts[ps.[2]] = count;
    }
}
var filtered = collisionCounts.Where(kv => kv.Value [3] 0).ToDictionary(kv => kv.Key, kv => kv.Value);
Drag options to blanks, or click blank then click option'
A>
Bname
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'length' instead of 'name'.
Using wrong comparison operators like '<' instead of '>'.