camera - Unity 2D Background Implementation -


i'm trying use fixed background. added image child of camera , sized fill view of camera. seems in unity player when run on android devices, background seems short. see blank space in left , right sides of screen. orthographic size 6.

this position plane or quad , scale fill screen. works both in orthographic , perspective. orthegrphic size doesnt matter.

step 1 - create plane object in scene.

step 2 - add script object created.

step 3 - script auto resize , position @ near clip

using unityengine;  public class fillscreenplane:monobehaviour {     public float lunityplanesize = 10.0f; // 10 unity3d plane     void update()     {         camera lcamera = camera.main;          if(lcamera.isorthographic)         {             float lsizey = lcamera.orthographicsize * 2.0f;             float lsizex = lsizey *lcamera.aspect;             transform.localscale = new vector3(lsizex/lunityplanesize, 1,lsizey/lunityplanesize);         }         else         {             float lposition = (lcamera.nearclipplane + 0.01f);             transform.position = lcamera.transform.position + lcamera.transform.forward * lposition;             transform.lookat (lcamera.transform);             transform.rotate (90.0f, 0.0f, 0.0f);              float h = (mathf.tan(lcamera.fov*mathf.deg2rad*0.5f)*lposition*2f) /lunityplanesize;             transform.localscale = new vector3(h*lcamera.aspect,1.0f, h);         }     } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -