0
0
Unityframework~10 mins

2D camera setup in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - 2D camera setup
Start Unity Project
Create 2D Scene
Add Main Camera
Set Camera to Orthographic
Adjust Camera Size & Position
Attach Camera Follow Script (optional)
Run Scene & Observe Camera View
This flow shows how to set up a 2D camera in Unity step-by-step, from creating the scene to adjusting the camera and optionally making it follow a player.
Execution Sample
Unity
Camera.main.orthographic = true;
Camera.main.orthographicSize = 5f;
Camera.main.transform.position = new Vector3(0, 0, -10);
This code sets the main camera to orthographic mode, adjusts its size, and positions it to view the 2D scene properly.
Execution Table
StepActionCamera ModeOrthographic SizePosition (x,y,z)Result
1Start Unity ProjectPerspective (default)N/A(0,0,-10)Camera in default 3D mode
2Set Camera to OrthographicOrthographicN/A(0,0,-10)Camera switches to 2D view
3Set Orthographic Size to 5Orthographic5(0,0,-10)Camera zoom level set for 2D
4Set Camera Position to (0,0,-10)Orthographic5(0,0,-10)Camera positioned to see 2D scene front
5Run SceneOrthographic5(0,0,-10)Scene displays with 2D camera view
💡 Setup complete; camera is ready for 2D gameplay view.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Camera ModePerspectiveOrthographicOrthographicOrthographicOrthographic
Orthographic SizeN/AN/A555
Position(0,0,-10)(0,0,-10)(0,0,-10)(0,0,-10)(0,0,-10)
Key Moments - 3 Insights
Why do we set the camera mode to orthographic for 2D games?
Orthographic mode removes perspective distortion, showing objects in the same size regardless of depth, which is essential for 2D visuals as shown in execution_table step 2.
What does changing the orthographic size do?
It changes the zoom level of the camera in 2D. A larger size shows more of the scene, a smaller size zooms in. This is clear in execution_table step 3.
Why is the camera positioned at (0,0,-10)?
Because the camera must be behind the 2D objects on the z-axis to see them. Unity's 2D objects are usually at z=0, so camera at z=-10 looks towards them, as in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the camera mode after step 2?
APerspective
BOrthographic
CIsometric
DNone
💡 Hint
Check the 'Camera Mode' column at step 2 in the execution_table.
At which step does the orthographic size get set to 5?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look at the 'Orthographic Size' column in execution_table rows.
If the camera position was set to (0,0,10) instead of (0,0,-10), what would happen?
ACamera would see the 2D scene correctly
BCamera would flip the scene upside down
CCamera would be behind the scene and see nothing
DCamera would zoom in automatically
💡 Hint
Recall that 2D objects are at z=0 and camera looks along negative z-axis as per variable_tracker.
Concept Snapshot
2D Camera Setup in Unity:
- Set Camera.main.orthographic = true to enable 2D view
- Adjust Camera.main.orthographicSize to control zoom
- Position camera behind scene (e.g., z = -10)
- This setup removes 3D perspective for flat 2D display
- Optional: add scripts to follow player for dynamic view
Full Transcript
This visual execution shows how to set up a 2D camera in Unity. First, the camera mode changes from default perspective to orthographic to remove 3D depth effects. Then, the orthographic size is set to control how much of the scene is visible, acting like zoom. The camera is positioned at (0,0,-10) so it looks at the 2D objects placed at z=0. The execution table tracks these changes step-by-step, and the variable tracker shows how camera properties update. Key moments clarify why orthographic mode is needed, what orthographic size does, and why camera position matters. The quiz tests understanding of these steps. This setup is essential for clear 2D game visuals in Unity.