How to create an old school camera switch when the player leaves/enters camera view


So i am fairly new to unity have been working on a small platforming game/demo. Now i have most of my animations and stuff like that working, but what i want is for locked off camera views, and another camera to activate when the player leaves the screen.

Like in the old platformer games like flashback/another world.
So how do i go about doing this ? any help thanks in advance.


For your scenario I recommend moving you camera rather than having multiple cameras in the scene.

The simplest way is to calculate and apply the ideal camera position with an algorithm similar to this:

float screenWidth = 10.0f // viewable area in world units
Vector3 cameraPos = camera.transform.postion;
Vector3 playerPos = player.transform.postion;
cameraPos.x = screenWidth * (Mathf.RoundToInt(playerPos.x / screenWidth) + 0.5f);
camera.transform.postion = cameraPos;

If you want precise control of camera positions is suggest setting up gameobjects with:

  1. a trigger collider; and
  2. a child GameObject to act as a placeholder
  3. a script so that on the OnTriggerEnter event it sets the camera position and rotation to match the child GameObject.

Then you need to set up enough of these so that the triggers cover the gameplay area, and the placeholders represent good camera angles.