Keeping the player to be within the screen

Hi!

Mine is 2D app.
The player moves only up and down.
The screen has a ground sprite. Its height is 300 pixels(0.3f).

I want to keep this player to be within the screen, because it flies out of the upper border of the screen.
The script for this as follows;

public class Boundary: Monobehaviour
{

just make a 2d collider at each side of the map.

Here is a great tut on that and also covers many other 2d things you may come across.

https://noobtuts.com/unity/2d-pacman-game

Hi, Kobaltic1

Much appreciation for your help.

You mean that a 2d collider must be set up along the upper borderline of the screen?
There is no any simple script to resolve this headache?

please don’t post duplicate threads about the same problem

Duplicate