2D Toolkit > Support
Dealing with pixel dimensions?
(1/1)
Gooms9:
Hey, I was wondering how I can tell how large something is in pixels? I've got my sprite which is 1024x768. But it's width and height in unity are both 0.75. Do I have to perform these calculations myself, or is there a convenience method that I can make use of for getting and setting its pixel dimensions?
unikronsoftware:
Unity has convenience functions to do these unit conversions. The two you'll need are:
camera.WorldToScreenPoint
and
camera.ScreenToWorldPoint
You can use this to calculate differences in position (eg. widths & heights) too. Make sure you pass correct z values in for this to work with a perspective camera. With an ortho camera, things are much much simpler - you simply do camera.WorldToScreenPoint(new Vector3(1,1,1)) and that gives you a conversion constant you can use to convert from world to screen space.
Navigation
[0] Message Index
Go to full version