• 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
0
Question by manuelsilverio01 · Nov 07, 2012 at 05:04 AM · android

Screen resolution set up Android

Hi, I'm making my first game for android.. I would like to know how to set the screen resolution properly so my game can be played in any android device.. a smartphone, or tablet... 4", 7", etc... right now I've only tested it on my 7" tablet.. but don't have a smartphone to test it

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by JCprogrammer · Jan 31, 2013 at 08:18 AM

actually i had this issue during my Android supported Casual game Development . there are things to do , mostly , it refers to the way you choose to solve it . there is not an exact Aspect ratio to set on , or something Automatically sets the default Resolution , on every android device for sure .

they way i thing would be the solution is to manipulate the aspect parameter from the camera ( Actually you default Camera ) . how to set it would be like this :

public Camera Cam1; // where you will set your default ( main ) camera

void Start() { Cam1.aspect = (Screen.currentResolution.width / Screen.currentResolution.height); //so this would stretch the game scene in order to adjust it to the Device's screen }

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 peaveyyyy · Jul 31, 2015 at 07:22 AM 0
Share

This works perfectly in the editor, though it obviously stretches images/objects to suit the screen,

HOWEVER

In Android deployment it fails and shows the camera background, meaning that the camera cannot see the scene any longer

avatar image
0

Answer by JCprogrammer · Jan 31, 2013 at 08:18 AM

there are actually other ways like using the Function " Screen.SetResolution() " so that you can define your own resolution . this is the way i didn't try actually , but it answered as i heard .

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
avatar image
0

Answer by DDelapena · Aug 14, 2013 at 06:27 AM

SetResolution works great for that particular level, but what if I wanted it to be a global adjustment setting for the entire game?

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
avatar image
0

Answer by RyanZimmerman87 · Aug 14, 2013 at 06:53 AM

Right now on my Android project I am setting the resolution in the Main Camera Script with:

 Screen.SetResolution(1280, 720, true);

Then I use a GUI.Matrix to format GUI elements:

 //any other script with GUI Components
 
 //formats GUI stuff easily
 public GUIStyle GUIStyleButton;
 
 //any kind of texture to use in OnGUI()
 public Texture2D inventoryTexture;
 
 float native_width = 1280;
 float native_height = 720;
 
 float rx;
 float ry;
 
 //position for texture
 vector2 buttonTexturePosition = New Vector2 (0,0); 
 
 //size for texture
 vector2 buttonTextureSize = New Vector2 (100,100);
 
 void Start()
 {
 //sets up matrix to adjust to any screenheight based on your native camera height
 rx = Screen.width/ native_width;
 ry = Screen.height / native_height;
 
 buttonTexturePosition.x = buttonTexturePosition.x *(Screen.width/native_width);
         
 buttonTexturePosition.y = buttonTexturePosition.y *(Screen.height/native_height);
 
 buttonTextureSize.x = buttonTextureSize.x * (Screen.width/native_width);
 
 buttonTextureSize.y = buttonTextureSize.y * (Screen.height/native_height);
 
 
 }
 
 void OnGUI()
 {
 //set matrix locally if necessary
 float rx = Screen.width/ native_width;
 float ry = Screen.height / native_height;
 
         
 GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (rx, ry, 1));
 
 if (GUI.Button (new Rect (buttonTexturePosition.x, buttonTexturePosition.y, buttonTextureSize.x, buttonTextureSize.y), inventoryTexture, GUIStyleButton))
 {
 //what button does this same thing can be used for GUI.Label without if condition
 }
 }
 

Not sure if there's a better solution but I was dreading trying to format for all Android devices but this method seems to so far work perfectly for me with both the camera and GUI components.

Comment
Add comment · Show 2 · 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 DDelapena · Aug 14, 2013 at 06:56 AM 0
Share

Cool, So I guess the answer is.. there is no global setting, it needs to be set per level.(mainCamera)

fyi- I fixed the issue with gui elements, by making them all 3d gameObjects. (lowered draw calls for me in the end, and easier performance wise on IOS devices lower then iphone4s )

thanks

-Dan

avatar image RyanZimmerman87 · Aug 14, 2013 at 07:04 AM 0
Share

Ya I've found that OnGUI() is surprisingly performance heavy, almost disturbingly so when used in certain ways according to the Unity Profiler. It's so easy to work with though that I haven't tried anything else yet.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Android Programming 1 Answer

Touch not changing variables, Keypress does 0 Answers

IAP Plugins on Android Unity Not Working For Me 1 Answer

How do i handle phone calls when game is running (android)?? 0 Answers

Access web-hosted game from iOS mobile? 0 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