Previously written about the 2D game interface camera's horizontal, vertical, people-centric three mode of camera control, I write, I wrote, always feel the camera is a bit cumbersome, and the adaptation is not very good, multi-platform time because of limited resources I do not know whether there is a complete adaptation, Today to share with you today I wrote a 2D game scene camera adaptation, feeling very good, there is a need to try, then I put the code:
Using unityengine;using System.collections;public class Cameracontrol_2d:monobehaviour { //default screen size float width = 854.0f; float height = 480.0f; Use the this for initialization Void Awake () { //screen to fit with float orthographicsize = this. Getcomponent<camera> (). orthographicsize; Print ("AA:" + orthographicsize); Orthographicsize *= (Screen.height/(float) screen.width)/(height/width); Print ("BB:" + orthographicsize); This. Getcomponent<camera> (). orthographicsize = Orthographicsize; }}
Unity's 2D Game Interface camera control