0
0
Unityframework~20 mins

2D camera setup in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
2D Camera Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this camera position code?

Consider this Unity C# script snippet that moves a 2D camera to follow a player object with a fixed offset. What will be the camera's position after running this code if the player is at (5, 3, 0)?

Unity
Vector3 playerPosition = new Vector3(5f, 3f, 0f);
Vector3 offset = new Vector3(0f, 2f, -10f);
Vector3 cameraPosition = playerPosition + offset;
Debug.Log(cameraPosition);
A(5.0, 5.0, -10.0)
B(5.0, 3.0, -10.0)
C(0.0, 2.0, -10.0)
D(5.0, 2.0, -10.0)
Attempts:
2 left
💡 Hint

Remember that adding vectors adds each component separately.

🧠 Conceptual
intermediate
1:30remaining
Which component controls the camera's zoom in a 2D orthographic setup?

In Unity's 2D camera setup using an Orthographic camera, which property controls how zoomed in or out the camera view is?

ACamera.nearClipPlane
BCamera.fieldOfView
CCamera.depth
DCamera.orthographicSize
Attempts:
2 left
💡 Hint

Orthographic cameras do not use field of view.

🔧 Debug
advanced
2:30remaining
Why does this 2D camera script cause jitter when following the player?

Given this Unity C# script attached to the camera to follow a player, why might the camera jitter during gameplay?

Unity
public Transform player;
void Update() {
    Vector3 newPos = player.position + new Vector3(0, 2, -10);
    transform.position = newPos;
}
ABecause the offset vector is incorrect and causes the camera to move erratically.
BBecause the camera position is updated in Update(), which runs before physics updates causing jitter.
CBecause the camera's z position is set to -10, which is invalid for 2D cameras.
DBecause the player Transform is not assigned, causing null reference errors.
Attempts:
2 left
💡 Hint

Think about when Update() runs compared to physics updates.

📝 Syntax
advanced
1:30remaining
Which option correctly sets the camera to orthographic mode in Unity C#?

Choose the correct line of code to set the main camera to orthographic mode.

ACamera.main.orthographic = true;
BCamera.main.SetOrthographic(true);
CCamera.main.isOrthographic = true;
DCamera.main.orthographicMode = true;
Attempts:
2 left
💡 Hint

Check the exact property name for orthographic mode.

🚀 Application
expert
3:00remaining
How many items are in the resulting dictionary after this camera layers setup?

Consider this C# code snippet that sets up a dictionary mapping layer names to their camera culling masks. How many entries does the dictionary contain?

Unity
var cameraLayers = new Dictionary<string, int>();
cameraLayers["Background"] = 1 << 8;
cameraLayers["Player"] = 1 << 9;
cameraLayers["Enemies"] = 1 << 10;
cameraLayers["UI"] = 1 << 5;
cameraLayers["Player"] = 1 << 11;
A3
B5
C4
D6
Attempts:
2 left
💡 Hint

Remember that dictionary keys must be unique and duplicate keys overwrite previous values.