How to keep player in screen?

Hey, I’m using Unity in 2D, but I can’t seem to find a way to keep the player from going
off the screen.

Now I have an idea on how to maybe implement this. Would I need to check the player position against the camera position?

any help would be appreciated. Thanks.

You can match the horizontal and vertical direction of the character to the camera, like this explanation by @robertbu.

Alternatively, why not parenting your camera to your 2D entity? Make the camera to be the child of the 2D entity if this fits. Would this work in your scenario?