< Back to Game Dev, Unity

Unity’s screen point, viewport point and world point

 While developing Error Hunter in Unity, I found out there were 3 ways to display a point on screen:

diagram demostrating screen points in Unity

Screen point: The points are the pixel values. You can use Screen.width and Screen.height to get the full screen dimensions. Neat.

unity-viewpoint

View Point: Here the screen width and screen height are always 1, and everything in between is a fraction. Since mobile devices come in all shapes and sizes, this is quite a good way to go about using view points too.

unity-worldpoint

….and then we have the World Point. It seems to have it’s own unique measurement. eg. when you use transform.position += transform.right; you move the object to the right by 1 amount of this special measurement. Also, I couldn’t find a way to get the screen width/height in this ‘world space’. Quite a headache.

So, world points suck and you shouldn’t use them right? Wrong! You can only move objects around in world space so everything has to be converted to that. Here’s what I did in Error Hunter:

Vector3 fullScreen = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,10));

I made a screen point in the top right and then converted it into world point. This allows me to use things like

 if (aRect.transform.position.y>fullScreen.y) {}

to check if something is going off screen.

Be Sociable, Share!

One thought on “Unity’s screen point, viewport point and world point

  1. Thank you. Glad I found this. This really helped me! Was clear and simple to help me understand Unity’s many systems of measurements.

Leave a Reply

Your email address will not be published. Required fields are marked *