- Home /
Android Screen Resolution.
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.
Describe what you mean by "fit". There's no need to change resolution yourself, Unity does it for you. The camera view frustum also scales with resolution.
Lets say I have a 5.1" device. If I set landscape orientation correct. Will I get same aspect of view on other devices with different screen sizes like 4 or 6 inches?
Answer by bilo-lwabona · Dec 26, 2013 at 12:38 PM
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
if you want to convert it to untiy units or convert unity units to pixels, here the the conversion 100 pixels= 1 unity unit this is for scaling non gui element
thank you this was awesomeee! but i cant make the health bar shorter :P
I have a similar problem. I am trying to fit my application in multiple Android devices,but I used 3D $$anonymous$$eshes and 3D Texts as buttons ins$$anonymous$$d of GUIs from code. So far, it is too small/wide depending on horizontal/vertical view on my galaxy s3. Any solutions?
Answer by sarthakshah · Sep 18, 2014 at 05:15 AM
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.
Answer by kirill-codecombat · Oct 19, 2016 at 02:38 PM
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!?!?!?!?!?!?!?!?!?!?
Your answer
Follow this Question
Related Questions
Android Resolution Problem 1 Answer
How can I fix the screen disturbance of android 4.1/4.2 ? 0 Answers
Android Screen Resolution 0 Answers
Divide resolution and stretch to screen/window/canvas 1 Answer
How to make a character move towards a side of the screen that's pressed at a constant rate? 2 Answers