Porting an HTML5 project to Unity

Hello all!

First, I’m new to Unity. I’ve only been working with the editor for a few weeks now, but I’m really enjoying it. I’m trying to port an existing 2D html5 game to Unity and am looking for some advice as to how I should go about loading level data to the scene. More specifically, getting the background sprites in a semi close proximity on the screen to where they are located in the original game. Via C#, I’ve successfully loaded all sprites and created prefabs for further use in the scene. I’m hitting a road block when it comes to positioning them on the screen. My camera (orthographic) size is set to 5 and PixelToUnit size is set to the default 100. I’m trying to figrue out what the best way to convert the sprites X/Y value (that is in pixels) to Unity Units. I thought that one of the camera functions ScreenTo{Viewport|World}point might be my answer, but I’ve not had much success with getting the assets plotted to the correct location. The same goes for the scaling of the sprites. Some of the sprites in the original game were either scaled up or down slightly. So my overall question is, what is the best way to handle porting a sprites location/size into unity without manually having to place all the objects by hand.

Thanks in advance for any help/suggestions/advice you can provide.

Most people will tell you to set the PixelToUnit size to 1 so that there is a 1:1 pixel:unit ratio. Then you can transfer values directly.

Another way is to change the orthographicSize of your camera to the height of your window.
So for instance if your window is 768 pixels height you’d set your orthographicSize to 7.68

This depends on your PixelToUnit value as well. if it was 1 you’d want your orthographicSize to be the same as the height of the window, if it’s 100 you want it to be 7.68

Here are some things to keep in mind:
Screen.width and Screen.height are integers. cast them to floats before using them in calculations with other floats.

Unity’s (0,0) is in the center of the screen. Screen’s (0,0) is in the bottom left.