- Home /
Calculate screen top and bottom postion
I need to figure this out for two reason and put it in two separate places for my game. Right now i have object spawning in hard code, I would like to spawn between top and bottom of the screen even with different screen sizes. The Second reason is that I need to stop the player from moving past the top and bottom of my camera view for all screen sizes. Can someone please help me I cannot find out how to do this anywhere.
Answer by RecyclingBen · Aug 07, 2017 at 12:22 AM
Camera.main.ScreenToWorldPoint(new Vector3(screen.width, screen.height, 0);
is going to return where the top-right of your screen is
Camera.main.ScreenToWorldPoint(Vector3.zero)
is going to return where the bottom left of the screen is
you can then get these coordinates however you'd like. hope this helped
your code has some typos:
Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
That is the correct line of code.