Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that doesn't match the method signature.
Confusing the parameter type with collision data.
✗ Incorrect
The method OnParticleCollision receives a GameObject parameter representing the other object involved in the collision. Naming it 'other' is common and clear.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AddComponent instead of GetComponent.
Using FindObjectOfType which searches the whole scene.
✗ Incorrect
GetComponent() returns the component of type T attached to the GameObject.
3fill in blank
hardFix 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'
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.
✗ Incorrect
To stop a ParticleSystem, use the Stop() method.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing errors.
Using a variable name not declared as parameter.
✗ Incorrect
The parameter name must be consistent. 'other' is used to represent the collided GameObject.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'length' instead of 'name'.
Using wrong comparison operators like '<' instead of '>'.
✗ Incorrect
We check if count > 0, use ps.name to get the particle system's name, and filter dictionary entries where value > 0.