Unity 4.3 iOS 2D Tutorial – Camera Projection

By | August 29, 2014

 

Unity Camera Project

Creating a 2D game in Unity 4.3 has become much easier then how it was in past versions.  Basic settings are set up automatically now, sprites are implemented and a whole lot more.  One important aspect of 2D games is using the orthographic projection instead of the perspective one.  This is already done for you when following the steps in the Creating a Unity 2D Project tutorial. From here on, we will go into depth about camera sizes and how it defines the dimensions of the viewport.

Camera Size

Unity 4 Camera SettingsUnity does a “Pixel by Unit” scaling.  By default Unity sets it at 100.  This means that per 100 pixels of a sprite image it is considered 1 unit in Unity.  So if you have an image that is 200×100 pixels Unity would say it’s 2×1 unit.

This is important when adjusting the viewport size for the iOS.  If the resolution of the iPhone is 640×320 you will want to adjust this accordingly.

Lets use an example of having a background image that’s 640 pixels tall with a unit ratio of 100.  To figure out  what size our orthographic camera should have we need to do some basic math.

We will start with 640 / 100 to figure out how many units tall the background image is.  640 / 100 = 6.4.   So far so good, but the orthographic camera’s Size property measures half the heigh of the screen which means the 6.4 units tall will be cut in half to 3.2.

If you change the Size property in the Camera Inspector that’s shown on the right, then the image should fit perfectly in the viewport.

 

Conclusion

Creating a 2D game in Unity 4.3 has become much easier with less hassle.  There are however some adjustments that need to be made when it comes to iOS.  Camera settings such as the Size property is very important when trying to fit all of your game assets in such a small screen.  Make the proper adjustments based on the “Pixel by Unit” property on your sprites and you should be set!