How can i stop my player get out of the screen view?

i want to make my player stop when he is getting out of the camera view for 2D how can i make this :smiley:

OnBecameInvisible()
you can use on this function whenever the gameobject is out of visibility of camera it get called and you can transform its position back to the camera view.

you can also use colliders to stop the player go out of the camera view