I need my camera to follow my player however I want to do it through code as I don’t want the camera to have the player’s rotation. This is why I don’t want it to be a child. I would like my camera to be like this :

but move with my player.

How would I do this through code?

One solution can be to reference the camera attached to the player in the player movement script. Then when you detect that your player move, you move your camera according to the displacement. This way your camera is not a child of your player and you can move it as you want.

I think that this way of moving the camera is fully described in the Unity tutorial here.

Here is the detailed video for your query:
[Unity 5 - Roll a Ball game - 3 of 8: Moving the Camera - Unity Official Tutorials - YouTube]

I presume @AhsanNaeem is Unity Staff, so I hate to contradict him.

But as of Unity 2018.3.6f, that video doesn’t work.

however, I found this video (Unity Camera Follow Player Tutorial (Free Assets & Scripts) - YouTube) which is so much better. Bonus, he adds cameral lag to the follow camera, and shows how to do so.