- Home /
How to get the screen size of what the camera sees
Basically, I am trying to create a game that requires the screen as player sees it to be divided into a grid of squares. I want to know the length and width of the visible area so that I can partition it appropriately. I also want to size the squares appropriately based on the same parameters. So far, I've played with Screen.width/height to no avail. I am not even sure what those numbers mean. When I use them, everything is way off from what I expected. Can anyone fill in the blanks?
Are you position World objects or GUITexture objects? Is the camera perspective or orthographic? Are you authoring this app for a specific resolution or will the resolution be changing like it would on Android?
Answer by smallbit · Jul 31, 2014 at 06:15 AM
Screen.widthe/height is what you seek, they return screen width/height starting from left up corner (Like this, if you want to divide the screen you just operate on that value, for instance screen.width/2,screen.height/2 returns the center of the screen. If you want to grid 10 items vertically, you just calculate step by step = screen.height/10 and than just do simple loop
float step = Screen.height/10;
for (int i=0;i<10;i++)
{
y = i*step; //use it than to move /instantiate your object etc
}
Your answer
Follow this Question
Related Questions
How to fix small viewPort in GameRoom? 0 Answers
Camera.ScreenToWorldPoint Not Giving Right Point 3 Answers
Clicking Trigger 1 Answer
Lock the screen 1 Answer
Camera Shake 4 Answers