0
0
Unityframework~10 mins

Collider2D types (box, circle, polygon) 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 BoxCollider2D component to the GameObject.

Unity
gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
ACircleCollider2D
BBoxCollider2D
CPolygonCollider2D
DRigidbody2D
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing CircleCollider2D or PolygonCollider2D instead of BoxCollider2D.
2fill in blank
medium

Complete the code to add a CircleCollider2D component and set its radius to 2.5.

Unity
var collider = gameObject.AddComponent<[1]>(); 
collider.radius = 2.5f;
Drag options to blanks, or click blank then click option'
ACircleCollider2D
BPolygonCollider2D
CEdgeCollider2D
DBoxCollider2D
Attempts:
3 left
💡 Hint
Common Mistakes
Using BoxCollider2D which does not have a radius property.
3fill in blank
hard

Fix the error in the code to add a PolygonCollider2D component.

Unity
PolygonCollider2D collider = gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
ACircleCollider2D
BBoxCollider2D
CCapsuleCollider2D
DPolygonCollider2D
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different collider type name that does not match the variable type.
4fill in blank
hard

Fill both blanks to create a BoxCollider2D and set its size to (5, 4).

Unity
var collider = gameObject.AddComponent<[1]>(); 
collider.size = new Vector2([2], 4);
Drag options to blanks, or click blank then click option'
ABoxCollider2D
BCircleCollider2D
CPolygonCollider2D
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using CircleCollider2D which does not have a size property.
Setting size with wrong values.
5fill in blank
hard

Fill the two blanks to add a PolygonCollider2D, set its path count to 1, and define a triangle shape.

Unity
var collider = gameObject.AddComponent<[1]>(); 
collider.pathCount = [2]; 
collider.SetPath(0, new Vector2[] { new Vector2(0,0), new Vector2(1,0), new Vector2(0,1) });
Drag options to blanks, or click blank then click option'
ABoxCollider2D
B1
CPolygonCollider2D
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using BoxCollider2D instead of PolygonCollider2D.
Setting pathCount to wrong number.