Full-screen background zoom in Unity

Source: Internet
Author: User

1 usingUnityengine;2 usingSystem.Collections;3 4  Public classBgpicscript:monobehaviour {5 6     //Use this for initialization7      Publicuitexture BG;8     voidStart () {9 TenDebug.Log ("Device Height:"+ Screen.width +"_"+screen.height); One  AUiroot root = gameobject.findobjectoftype<uiroot>(); -  -         if(Root! =NULL)  the         { -             //Ultimate Big kill device overall resource scaling -             floats = (float) Root.activeheight/Screen.height; -             intHeight = mathf.ceiltoint (screen.height *s); +             intwidth = mathf.ceiltoint (Screen.width *s); -            +Debug.Log ("screen width By design Resolution ="+ width +"_height ="+height); A  atDebug.Log ("background Image Design resolution Bgwidth:"+ Bg.width +"_bgheight:"+bg.height); -  -             floatBgratio = (float) Bg.width/Bg.height; -             floatManualratio = (float) Width/height; -  -  in             if(Bgratio < Manualratio)//to zoom in on the background image by width as the black edge appears on both sides of the screen height zoom level -             { to                 //bg.width = width; +                 //bg.height = mathf.ceiltoint (width/); -  the                 floatTargetscale = (float) Width/Bg.width; *Bg.transform.localScale =NewVector3 (Targetscale,targetscale,1); $             }Panax Notoginseng         } -  the        +     } A      the     //Update is called once per frame +     voidUpdate () { -      $     } $ } -  -  the  - usingUnityengine;Wuyi usingSystem.Collections; the  -  Public classUirootscript:monobehaviour { Wu  -     //Use this for initialization About     voidStart () { $ Adaptiveui (); -     } -      -     //Update is called once per frame A     voidUpdate () { +      the     } -  $     Static Private voidAdaptiveui () the     { the         intManualwidth =1024x768; the         intManualheight =768; theUiroot Uiroot = gameobject.findobjectoftype<uiroot>(); -         if(Uiroot! =NULL) in         { the             if(System.Convert.ToSingle (screen.height)/screen.width > System.Convert.ToSingle (manualheight)/manualwidth) theUiroot.manualheight = Mathf.roundtoint (System.Convert.ToSingle (manualwidth)/screen.width *screen.height); About             Else theUiroot.manualheight =Manualheight; the         } theDebug.Log ("uiroot Height:"+uiroot.manualheight); +     } -}

Full-screen background zoom in Unity

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.