Make a camera follow an object

I wanna make a simple 2D game, but I need some code for my camera…
126073-pleasehelpme.png

I want to make that the camera moves only if the player goes in the green area…
So, the player can move freely in the white, without any camera movement!
Is this possible, and could you help me?

You have to firstly check where the player is. If the player is in green, you can parent the Camera.main to the player. And when the player returns into the white area, you have to unparent the main camera and set it’s fixed position.

OK, I just discovered the “CameraFollow” script in Unity Standard Assets / 2D / Scripts.
It’s, I think, the best way to solve this.

There is several ways to do this. Either you just let the camera transform follow the player transform.


You can use some default scripts like the one you mentioned. The most sophisticated way would be using Unity Cinemachine - where you have a shitload of settings to define the exact flow of the follow (delay, x y follow, some “free space” for the character to move where the cam will stand still and so on)