How can I make my game screen fit any android device? There are tons of android devices out there. It has been bothering me for days. Does anyone here has a script for that? I’d appreciate it.
[32562-screen+shot+2014-09-18+at+10.42.17+am.png|32562]
First of all you need to take one resolution (here i consider 1280*800 resolution with orthographic camera), and then find aspect ratio ,
aspect_ratio = width/height (aspect_ratio = 1280/800 = 1.6), then use following code.
in it ,5.0 is camera size
void Start()
{
Camera.main.projectionMatrix=Matrix4x4.Ortho(-5.0f*1.6f,5.0f*1.6f,-5.0f,0.5f,0.3f,1000f);
}
syntax :- Matrix4x4 Ortho(float left, float right, float bottom, float top, float zNear, float zFar);
see attached image , which is my camera settings.
Sameway, if you have perpective camera, you need to use " Matrix4x4 Perspective(float fov, float aspect, float zNear, float zFar);"
Hope will help you.
You don’t need to worry much about the actual physical screen size, but rather about the screen resolution. In terms of the game world, the final projected image may appear differently, based on the aspect ratio of the device’s display.
What you do need to pay attention to is the 2D GUI (if you have one). This uses coordinates in screen space (i.e. pixels). In order to make this work, you need to use percentages (which are relative to the screen size) in order to make your UI elements appear consistently across varying devices. For example:
Screen.width
and Screen.height give you the screen size of the device currently running the game, in pixels.
If you want a health bar to take up half the screen width and 5% of the screen height, you could do this:
Rect healthBarRect = new Rect(0f, 0f, 0.5f * Screen.width, 0.05f * Screen.height);
of course this will start the rectangle in the top left corner of the screen, but you can do something similar with the Screen dimensions for the x and y components of the rectangle’s top left corner.
Hope this helps.
Cheers
Bilo
Hi guys do you know how to make a game fit on android screen size because i was searching every ware and i only found how to do this with the ui.Can someone help me please!?!?!?!?!?!?!?!?!?!?