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
0
Question by N1warhead · Nov 20, 2014 at 05:20 AM · androidmobileresolution

Android Screen Resolution (Joysticks) help.

Hey guys, I've tried every single help information on getting the GUI's to stay scaled for every screen resolution, but it just doesn't work!

I 0 out all the Pixel Insets, change the scale to my liking and position the Joysticks where I want.

Well, what happens is, if I 0 out the Width and Height (In Pixel Inset) I can no longer use the Joysticks.

Well that problems number 1.

Problem number 2 is, they are never scaled with any droid I use.

Figured it might have been my G3 with 4K Resolution, well nope. I tried with my Ellipsis 7 Tablet at 720P and it's still not right.

Both Joysticks become super small like they are 5 x 5 in pixels and only take the first half of the screen no matter which device I use.

Please help me guys!

Comment
Add comment · Show 3
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 N1warhead · Nov 20, 2014 at 05:26 AM 0
Share

Oh yeah, forgot to mention (It stays perfectly aligned) IN (GA$$anonymous$$E VIEW) In the editor, it's only when I actually deploy to phone.

I try changing to all the resolutions in Game View and it works. It's only on Phone or Tablet where it messes up.

avatar image zharik86 · Nov 20, 2014 at 08:17 AM 0
Share

Are you use for Joysticks GUITexture or draw it in function OnGUI()?

avatar image N1warhead · Nov 20, 2014 at 08:22 AM 0
Share

I'm using the Joysticks GUITexture that came with the Standard Assets ($$anonymous$$obile) package.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by zharik86 · Nov 20, 2014 at 08:37 AM

Ok, for different resolutions of the android (or other screens), it is necessary to scale your GUITextures and GUIText. I will write a small explaining script (I write on CSharp):

  //define here the original resolution 
  public float origW = 1280;
  public float origH = 720;
 
  void Start() {
   float scaleX = (float)(Screen.width) / origW; //your scale x
   float scaleY = (float)(Screen.height) / origH; //your scale y
   //Find all GUIText object on your scene
   //Update 1: for C# add "typeof"
   GUIText[] texts =  FindObjectsOfType(typeof(GUIText)) as GUIText[]; 
   foreach(GUIText myText in texts) { //find your element of text
    Vector2 pixOff = myText.pixelOffset; //your pixel offset on screen
    int origSizeText = myText.fontSize;
    myText.pixelOffset = new Vector2(pixOff.x*scaleX, pixOff.y*scaleY); //new position
    myText.fontSize = (int)(origSizeText * scaleX); //new size font
   }
   //Find all GUITexture on your scene
   //Update 1: for C# add "typeof"
   GUITexture[] textures =  FindObjectsOfType(typeof(GUITexture)) as GUITexture[];
   foreach(GUITexture myTexture in textures) { //find your element of texture
    Rect pixIns = myTexture.pixelInset; //your dimention of texture
    //Change size pixIns for our screen
    pixIns.x = pixIns.x * scaleX;
    pixIns.y = pixIns.y * scaley;
    pixIns.width = pixIns.width * scaleX;
    pixIns.height = pixIns.height * scaleY;
    //Sets new rectangle for our texture
    myTexture.pixelInset = pixIns;
   }
  }

That's all. Attach this script to any object, for example, Main Camera. I hope that it will help you.

Comment
Add comment · Show 7 · 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 N1warhead · Nov 20, 2014 at 09:05 AM 0
Share

I'm getting a few errors

First one -

 Assets/_Imported/_Scripts/_GUI/_GuiFixedResolution.cs(13,35): error CS1502: The best overloaded method match for `UnityEngine.Object.FindObjectsOfType(System.Type)' has some invalid arguments
 
 
 (SECOND ONE)
 
 Assets/_Imported/_Scripts/_GUI/_GuiFixedResolution.cs(13,35): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Type'
 
 
 (THIRD ONE)
 
 Assets/_Imported/_Scripts/_GUI/_GuiFixedResolution.cs(21,59): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
 
 (FORTH ONE)
 
 Assets/_Imported/_Scripts/_GUI/_GuiFixedResolution.cs(21,41): error CS1502: The best overloaded method match for `UnityEngine.Object.FindObjectsOfType(System.Type)' has some invalid arguments
 
 (FIFTH ONE)
 
 Assets/_Imported/_Scripts/_GUI/_GuiFixedResolution.cs(21,41): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Type'
 
 
 

Can you help guide me on how to fix this? I'm using 4.6 if that helps.

avatar image zharik86 · Nov 20, 2014 at 09:51 AM 0
Share

I update my answer and remove error (I hope).

avatar image N1warhead · Nov 20, 2014 at 09:54 AM 0
Share

Doesn't look any different LOL. I mean it doesn't appear updated lol.

(I appreciate you trying to help me though!)

avatar image N1warhead · Nov 20, 2014 at 09:59 AM 0
Share

SWEET NO ERRORS!

avatar image zharik86 · Nov 20, 2014 at 10:01 AM 0
Share

I at first wrote the comment, and then update of my answer. Simply for the FindObjectsOfType() it is necessary to add "typeof" inside. See my answer. Below comments with name "Update 1:".

Show more comments
avatar image
0

Answer by N1warhead · Nov 20, 2014 at 10:57 AM

Not sure if you're script helped getting it to work, but I found this one and its working I APPRECIATE YOUR HELP THOUGH BUDDY!

But here is the code I found that works.

     public Vector2 scaleOnRatio1 = new Vector2(0.1f, 0.1f); 
     private Transform myTrans; 
     private float widthHeightRatio;
 
 
     // Use this for initialization
     void Start () {
         myTrans = transform;
         SetScale();
     }
     
     // Update is called once per frame
     void SetScale()
     {
         //aspect ratio
         widthHeightRatio = (float)Screen.width/Screen.height;
         //Apply the scale. We only calculate y since our aspect ratio is x (width) authoritative: width/height (x/y)
         myTrans.localScale = new Vector3 (scaleOnRatio1.x, widthHeightRatio * scaleOnRatio1.y, 1);
     }
 }
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

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

Related Questions

Multiple Cars not working 1 Answer

How do I reset Screen.sleepTimeout's user input timer? 1 Answer

why my Unity Android game close at random time after start on some devices. 1 Answer

Huawei P20 Pro Safe Area Issue 1 Answer

A node in a childnode? 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