0
0
Unityframework~10 mins

2D camera setup 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 set the camera to orthographic mode.

Unity
Camera.main.orthographic = [1];
Drag options to blanks, or click blank then click option'
Atrue
Bnull
Cfalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting orthographic to false keeps the camera in 3D mode.
Using null or 0 causes errors.
2fill in blank
medium

Complete the code to set the orthographic size of the camera to 5.

Unity
Camera.main.orthographicSize = [1];
Drag options to blanks, or click blank then click option'
A10
B-5
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero or negative values causes no visible view or errors.
Using too large values zooms out too much.
3fill in blank
hard

Fix the error in the code to move the camera to position (0, 0, -10).

Unity
Camera.main.transform.position = new Vector3([1], 0, -10);
Drag options to blanks, or click blank then click option'
A0
B1
C10
D-10
Attempts:
3 left
💡 Hint
Common Mistakes
Setting x to 10 moves the camera off-center.
Using -10 for x is incorrect here.
4fill in blank
hard

Fill both blanks to smoothly follow the player on the x and y axes.

Unity
Vector3 targetPosition = new Vector3(player.transform.position[1], player.transform.position[2], -10);
Drag options to blanks, or click blank then click option'
A.x
B.y
C.z
D.position
Attempts:
3 left
💡 Hint
Common Mistakes
Using .z would follow depth, which is not needed in 2D.
Using .position twice is incorrect syntax.
5fill in blank
hard

Fill all three blanks to clamp the camera's x and y position within limits and keep z at -10.

Unity
float clampedX = Mathf.Clamp(player.transform.position[1], [2], [3]);
float clampedY = Mathf.Clamp(player.transform.position.y, -5, 5);
Camera.main.transform.position = new Vector3(clampedX, clampedY, -10);
Drag options to blanks, or click blank then click option'
A.x
B-3
C3
D.y
Attempts:
3 left
💡 Hint
Common Mistakes
Using .y instead of .x for clamping x position.
Swapping min and max values in clamp.
Not clamping the x position at all.