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 Celovis · Mar 10, 2014 at 01:16 PM · screenscreen resolutionunity-android

Android: ScreenResolution/Scaling Script

Preface : I am new to Unity.

Here we are....

I have read over countless posts, but none of them give a simple solution to the question:

How do I make my app scale properly to any android screen resolution/size?

I stumbled upon a members script (CarterG81's Code), the only problem is that if I use his default PixelsPerUnit scaling, I get insanely large sprites. To fix this, I figured the best way to do it would be to scale the PPU variable depending on the devices screen dimensions (Screen.currentResolution.width or height).

Here is a bit of the code:

 using UnityEngine;
 using System.Collections;
 
 
 
 public class ResolutionCorrection : MonoBehaviour {
     
     public float adjusted;    
     void Awake () {
 
         // ORIGINAL 16:10 Aspect Ratio
         // Base resolution width = 1280
 
         adjusted = 40.0f * (Screen.currentResolution.width/1280.0f);
     }
     
     
     void Update () {
         
 
         this.camera.orthographicSize = Screen.height * gameObject.camera.rect.height / adjusted / 2.0f;//- 0.1f;
 
         
     }
     
 }




The original code did not scale the PixelPerUnit variable based on the screen size (i.e., if your screen size is half the size of the default resolution, you half the PPU variable (in this case, from 40 to 20)).

Now, this script does work, but it is janky. I almost need to set a dedicated c# to each camera, on each scene, in order to make each scene look properly. (e.g., the intro screen will be scaled perfected, but the next scene is huge). Whenever I fix the resolution error using this method, my parallax screen speed changes, which no longer matches game objects that are moving on my main camera (parallax uses its own camera).

Is there anyway to fix this issue? It is almost as if I could make a universal script that anyone could just drag and drop on their cameras to fix the issue. If I find an answer, I will post it, so that you guys have access to it. Sorry for the long post (it is shorter than I thought it would be, but I managed to get the eye tracking to control the gameObjects by using a c# wrapper for some of my C++ code, but that is neither here nor there :D)

I love you all.

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 Celovis · Mar 10, 2014 at 10:36 AM 0
Share

adjusted = 40.0f * (Screen.width/1280.0f);

Corrects some issues. I used a variable default size (the 1280.0f was labeled as a public float in my testing phase. It works better than anticipated. I can get my whole app to resize (save one page that only contains TWO sprites (one I used as a background, yeah, I know that was bad.)

avatar image CarterG81 · May 31, 2014 at 12:04 AM 0
Share

So...did you get it working or still need help?

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Android Screen Resolution. 3 Answers

GameObject or Screen Size Shrink? 1 Answer

Screen.width and Screen.currentResolution returning unwanted value 0 Answers

How can I fix the screen disturbance of android 4.1/4.2 ? 0 Answers

Android Resolution Problem 1 Answer


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