Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Nick4 · Dec 26, 2013 at 01:09 AM · androidscreenscreen resolution

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Dec 26, 2013 at 06:32 AM 0
Share

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.

avatar image Nick4 · Dec 26, 2013 at 10:43 AM 0
Share

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?

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nick4 · Dec 26, 2013 at 04:05 PM 0
Share

Thanks for awesome answer!

avatar image UnityDevelopper · Jun 15, 2014 at 11:12 PM 0
Share

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

avatar image muhammed0213 · Sep 04, 2014 at 05:16 PM 0
Share

thank you this was awesomeee! but i cant make the health bar shorter :P

avatar image kuos · Sep 18, 2014 at 02:18 AM 0
Share

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?

avatar image
7

Answer by sarthakshah · Sep 18, 2014 at 05:15 AM

alt text

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.


screen shot 2014-09-18 at 10.42.17 am.png (38.2 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image camillo777 · Apr 20, 2015 at 01:15 PM 1
Share

This worked! Awesome!

avatar image
0

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!?!?!?!?!?!?!?!?!?!?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges