Camera border

I’m trying to make an Android top-down shooter game (spaceship only moves on X and Y axis) for my first Unity project and I’m running into difficulty. The camera will be fixed and I want the player spaceship to be within the screen. How would I create a barrier around the screen?

I was looking at Camera.WorldtoScreenPoint but in testing it seems like it’s more the physical camera bounds which may exceed the screen bounds. I used the code found here and it said I hadn’t reached 0 until I was well off the screen.

I also can’t do a static barrier because Android screen sizes vary.

I’m trying to find some way to relate an XY position on the screen (Z position will always be exactly the same distance from camera) to an XY position in space. I also need this for things like boss fights where I want the boss to go to specific areas on a screen (like in a circle around the screen while the player has to dodge). How would I do this?

Is it a 2D top-down? If so just make everything 2D textures and work with viewport space interval.