CodeBlanks Logo Icon CodeBlanks

Camera and light

Learn to add and position a Main Camera and a Directional Light.

Main Camera

The Main Camera determines what the player will see while the game runs. Every new scene comes with a default Main Camera, listed under that name in the Hierarchy window. You set its position with the Position fields in the Inspector.

Main Camera
Position: X = 0, Y = 1, Z = -10

This position keeps the camera slightly above and behind the scene, so you look down at the scene.

Directional Light

A Directional Light gives flat light coming from a single direction, like the sun, and brightens the objects in the scene. Every new scene has one by default; you set the incoming direction with its Rotation values. A typical angle makes the light come from above and from the side.

Directional Light
Rotation: X = 50, Y = -30, Z = 0

Without a light the cube looks flat and dark, so you place the light together with the camera in the first step.

Practice Print the camera position

Hold the camera position in three int variables as kameraX = 0, kameraY = 1, kameraZ = -10. Print the three values on a single line with the heading "Kamera konumu: ". Expected output:

Kamera konumu: 0, 1, -10

Starter code

Player.cs
using System;

class Sahne {
    static void Main() {
        // Kamera konumunu uc int degiskende tut: 0, 1, -10
        // "Kamera konumu: " basligiyla uc degeri tek satirda yazdir
    }
}

Sample solution

Player.cs
using System;

class Sahne {
    static void Main() {
        int kameraX = 0, kameraY = 1, kameraZ = -10;
        Console.WriteLine("Kamera konumu: " + kameraX + ", " + kameraY + ", " + kameraZ);
    }
}

Expected output

Kamera konumu: 0, 1, -10

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does the Main Camera determine in the scene?

  • The weight of the objects
  • What the player will see in the scene Correct answer
  • The color of the cube
  • The intensity of the light

Explanation: The Main Camera is the player's window on the world; whatever the camera sees is what appears on screen.

2 Write the light's incoming angle

Question
int isikRotX = ____; // Directional Light icin egim
Answer
int isikRotX = 50; // Directional Light icin egim

Explanation: On the card, the X axis of the Directional Light rotation is 50 degrees.

3 Camera and light parts

Term Meaning
Main Camera Determines what the player sees
Directional Light Lights the scene from a single direction
Position: 0, 1, -10 The camera's position
Rotation: 50, -30, 0 The light's incoming angle

All lessons in Beginner