2D Style Camera, Shifting at Screen Edge

Hey, I’m pretty new to scripting and Unity but I’ll try my best to convey my issue.

My question, if you wish to help:

In a 2D-style platformer, how can the camera stay fixed on a “room” until the character reaches a side of the screen and walks off, prompting the camera to shift to the section he’s entering?

I think I could start off with either:

  1. Triggerwalls in each room that shift camera over
  2. Calculate screen edges in real world space, if player exits shift that way
  3. Set empty object in center of room, raycast to player

Any thoughts?

I think the easiest way would be to have a script keep track of the player’s position in view space since it sounds like you’ll wanna tweak this behavior.

void Update() {
    Vector3 viewPosition = camera. WorldToViewportPoint(player.transform.position);

    if( viewPosition.x > 0.9f ) // move right
    else if( viewPosition.x < 0.1f ) // move left

    // etc