0
0
Unityframework~10 mins

3D colliders 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 add a BoxCollider component to the GameObject.

Unity
gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
ARigidbody
BSphereCollider
CBoxCollider
DMeshRenderer
Attempts:
3 left
💡 Hint
Common Mistakes
Using SphereCollider instead of BoxCollider.
Adding MeshRenderer instead of a collider.
2fill in blank
medium

Complete the code to check if the GameObject has a Collider component.

Unity
if (gameObject.GetComponent<[1]>() != null) {
    Debug.Log("Collider found");
}
Drag options to blanks, or click blank then click option'
ACollider
BTransform
CRigidbody
DMeshFilter
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for Rigidbody instead of Collider.
Checking for Transform which is not a collider.
3fill in blank
hard

Fix the error in the code to detect collision with another object.

Unity
void OnCollisionEnter(Collision [1]) {
    Debug.Log("Collided with " + [1].gameObject.name);
}
Drag options to blanks, or click blank then click option'
Ahit
Bcollision
Cother
Dcollider
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'collider' which is a different component.
Using 'other' or 'hit' which are not standard parameter names here.
4fill in blank
hard

Fill both blanks to create a dictionary of GameObjects and their BoxCollider sizes where the size's x dimension is greater than 1.

Unity
var bigColliders = new Dictionary<GameObject, Vector3>() {
    { [1], [2].size }
};
Drag options to blanks, or click blank then click option'
AgameObject
BGetComponent<BoxCollider>()
Ctransform
DGetComponent<Rigidbody>()
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of gameObject as key.
Using Rigidbody instead of BoxCollider to get size.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps GameObjects to their collider bounds size if the collider is enabled and size x is greater than 0.5.

Unity
var colliderSizes = new Dictionary<GameObject, Vector3>() {
    { [1], [2].bounds.size }
} where [3].enabled && [2].bounds.size.x > 0.5;
Drag options to blanks, or click blank then click option'
AgameObject
BGetComponent<Collider>()
CGetComponent<BoxCollider>()
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform as key instead of gameObject.
Using BoxCollider instead of Collider for bounds.
Not checking if collider is enabled.