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 DFiable · Jun 25, 2012 at 01:44 PM · guiiphoneresolutionscale

How do I Scale a GUITexture or GUIText for different resolutions screen sizes on the iPhone?

My "buttons" rescale perfectly with the code below using the OnGUI function, regardless of what iPhone or iPad I'm testing on. I added the GUI.matrix code line directly below the OnGUI function. My question is, How do I rescale a GUITexture or a GUIText? Since these game objects are created by Unity I'm unable to edit the script and add this line of code.

thanx

 function OnGUI() {
 GUI.matrix = Matrix4x4.TRS(Vector3.zero,Quaternion.identity,new Vector3(Screen.width/960f,Screen.height/640f,1f));
 
 if (GUI.Button(Rect(30,210,170,55),"PLAY INTRO"))
      
   
      Application.LoadLevel("sk38");
      
 
 
 Time.timeScale =1;
 }
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

1 Reply

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

Answer by Wolfram · Jun 25, 2012 at 02:01 PM

My answer here describes the approach for scaling GUITextures correctly for varying screen resolutions. In your case, option "2)" is what you are looking for. Although that answer only describes the scaling in detail, you can do similar computations for the positioning of your GUITextures.

GUITexts behave somewhat different, they ignore localScale and only use font size, and the positioning is done with localPosition (view space) and/or pixelOffset (screen space) from that localPosition, plus the given anchor property. I guess the fact that it's so complicated to deal with the "old style" GUIElements was one of the reasons (besides flexibility) to create the new UnityGUI classes.

An entirely different approach would use "real" 3D obejcts placed in a parallel plane as child to the camera in a normalized screenspace, see here for example.

What do you mean by "these game objects are created by Unity"? You still have to create these assets and place them in your scene. Note that OnGUI() is entirely unrelated to GUIText/GUITextures.

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 DFiable · Jun 25, 2012 at 04:06 PM 0
Share

Thank you! That works great!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Dealing with GUI size on iPhone 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Scaling GUI When Screen Width is Adjusted 1 Answer

How to create a resizable GUI 1 Answer

Scaling the GUI with different screen resolutions 6 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