Is there a function for converting transform to screen coordinates?

Hi all,

In using GUITextures, their location on screen is given by the Transform component, which seems to have a “percentage”-type coordinate which ranges from 0.0,0.0 (lower left of the screen) to 1.0, 1.0 (upper right of the screen), instead of the actual pixel location on screen. Given the different screen sizes on which Unity can operate, I can see why this would make sense. However, when detecting Touch coordinates, these are returned in their actual pixel positions, and not in the percentage-type coordinate.

Right now, I have to rely on formulas to convert from one coordinate system to another, but my math isn’t that good. Doesn’t Unity include a function to convert between these? It’s really hard to deal with two different coordinate systems when using GUITextures.

Thanks for any information.

The only thing you need to do to get the screen position is:

Input.touches[0].position.x / Screen.width;
Input.touches[0].position.y / Screen.height;

And you’ve got the location of your transforms from 0 to 1…

To convert back:

transform.position.x * Screen.width;
transform.position.y * Screen.height;

Easiest conversions ever :D.