hello, i’m working on a 2d side scroller game, I’m wondering if is there a way to know the size of my entire level in pixels ?
i’m currently using an orthographic camera with it’s size set to 7 and the pixel per units of my sprites and textures are set to 100.
what type of math or calculation can i do (using the above specifications) to convert units to pixels if for example i have a big 2dbox that covers all my entire level and it is width=58 and height=18?
thanks in advance for all your help.
I would probably loop through all sprites, finding the minimum and maximum positions, and find the distance between them. To convert to pixels, you would multiply by your PixelsPerUnit value that you use for your sprites. That usually defaults to 100 if you haven’t changed it.
if i put a box (for calculation purposes only) that is wide x=1 and i scale it on ScaleX=58, my level width will be 5800 pixels ? i’m right ?
If you mean it’s 1 unity unit wide with a Pixels Per Unit of 100 (meaning your sprite is 100 pixels wide in order to equal 1 unity unit), then yes 5800 pixels wide if x scale is 58.
Unity Unit Width * Pixels Per Unit = Pixel Width
Therefore:
Pixel Width / Pixels Per Unit = Unity Unit Width
Scale is just a multiplier to the size regardless of units.
1 Like
thank you for the information jeffreyschoch!
1 Like