Hello Guest

Author Topic: Dealing with pixel dimensions?  (Read 8428 times)

Gooms9

  • Newbie
  • *
  • Posts: 3
    • View Profile
Dealing with pixel dimensions?
« on: January 27, 2012, 06:11:16 pm »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dealing with pixel dimensions?
« Reply #1 on: January 27, 2012, 06:41:08 pm »
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.