There are several ways in making the camera follow the player, the most simple way is to drag the camera game object and make it a child of the player component but that leaves much to desire, especially since Unity has implemented special features within “Cinemachine” for better camera control.
Setting Up Cinemachine:
First we need to download the Cinemachine asset from the Package Manager.
Download and install, and automatically there should be a new dropdown menu on the very top of Unity called “Cinemachine”.
To create a new virtual camera click the dropdown menu and select “new Virtual Camera”, this should create a new CM Virtual Cam within the hierarchy.
Within the virtual camera, you will see that there is a “Follow” function in the Inspector. Drag and drop the player component into this slot, and automatically you will see that the camera focuses on the player and follows the player as it moves around, including up and down movement.