This tutorial explains how to create a camera system that follows the player character in a 2D platformer game.
<aside> 💡
For this tutorial you need some sort of movement for the player.
The final state of the Platformer 2D Player Object tutorial is used as a base.
Alternatively, download the project in its final state of the tutorial above here:
</aside>
First of all, understand that any type of game requires some type of visuals. That essentially involves a Camera.
Your default screen should contain a Main Camera GameObject, which is used to render the scene the way you see it displayed in the Game window.
<aside>
💡 If you don’t have a GameObject with a camera, create a new one with a right click in the hierarchy window, on using the GameObject menu on top, then Camera.

</aside>
Our first approach is simple: The idea of following means matching the positions of the entity that is being followed.
Create a new Script named CameraFollow and add a Transform variable to reference the object that will be followed. Add a line into the Update function to match the positions of the objects.
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
[SerializeField] Transform objectToFollow;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = objectToFollow.position;
}
}
Attach the script to the Main Camera object and drag the player object to the ObjectToFollow slot.
If you simulate the scene you’ll notice that the camera actually follows the player in the Scene window, but the Game window displays only the blue color of the background.