Detecting the Edge of the Screen

So I need a way to detect the edges of the screen regardless of it’s formatting, for my Space Invaders style game. Or, is it possible to resize the screen so that the game is always the same size?

Also, I need a way to pause the game when you win (or lose), so that the player has time to see the text of “you win” or “you lose” before the application closes through Application.Quit();

To stop object at edge of screen:

Vector3 viewPos = Camera.main.WorldToViewportPoint(transform.position);
viewPos.x = Mathf.Clamp01(viewPos.x);
viewPos.y = Mathf.Clamp01(viewPos.y);
transform.position = Camera.main.ViewportToWorldPoint(viewPos);

Note that as the screen resizes, so does the Camera, so you should only see you original issue if the aspect ratio changes.

What do you mean ‘edges of the screen’? Do you mean the rendered window that the game runs in, or the physical device’s screen? And what do you mean by ‘detect’?

If I understand you at all, you may want to operate in Viewport space which has units from 0 to 1, always. See: