Camera Placement in Platformer
Object: Use Cinemachine to position main camera as player moves in game.
In Unity select window > package manager then search for Cinemachine and install, see below.
Create an empty object called Camera_Progression to store ten virtual cameras (vcam) created from the cinemachine (CM) menu now available in Unity. For each vcam disable the CinemachineVirtualCamera, uncheck, and click on solo to show the virtual cameras view in the game window, see below. Do the same for the other nine CM_vcams, selecting views that cover the various platforms in the game. The main camera fill move to focus on a local area of the level as the player moves through the game.
Now create an empty game objects named Camera_Triggers. Create another empty game object, naming it Camera_1_Trigger, as a child of Camera_Triggers, and add a box collider with is trigger checked. Edit the collider so the it is slightly above the platform, as shown above. Change the layer to Ignore Raycast. Create a C# script that triggers when the Player enters the collider the main camera switches to a position and rotation covering this box collider.
Duplicate this nine times. Edit the colliders for Camera_1–10_Trigger to correspond to the view from the corresponding CM_vcam1–10.
The hierarchy window should look similar to that shown below.
Finally attach the following LookAtPlayer script to the main camera to allow the camera to focus on the Player as they move through the game. To do this the Transform of the _player is grabbed in void Start(), and Camera.main.transform.LookAt is used to focus on the _player.