Unity2d screen Adaptation Scheme

Source: Internet
Author: User

Read an article in Cnblogs, finally understand the Unity2d camera system: http://www.cnblogs.com/flyFreeZn/p/4073655.html

According to his plan, I rewrote two adaptation schemes: FixedWidth and Fixedheight, which is to lock one of the variables to fit the screen.

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classGamecamera:monobehaviour {5      Public stringScaleMode ="fixedwidth";6 7      Public floatDesignwidth =9.6f;8      Public floatDesignheight =16f;9     Ten     //Use this for initialization One     voidStart () { A         floatAspectratio = Screen.width *1.0f/Screen.height; -         floatOrthographicsize =0; -  the         Switch(scaleMode) { -          Case "fixedwidth": -Orthographicsize = Designwidth/(2*aspectratio); -              Break; +          Case "fixedheight": -Orthographicsize = designheight/2; +              Break; A         } at  -          This. Getcomponent<camera> (). Orthographicsize =orthographicsize; - Debug.Log (orthographicsize); -     } -      -     //Update is called once per frame in     voidUpdate () { -          to     } +}

You can modify the design size and remember that the design size is scaled by 1:100 scale.

Unity2d screen Adaptation Scheme

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.