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 aman_jha · Jul 29, 2014 at 02:48 AM · c#androidguitextfield

Unity Scale One Text Field GUI

Hey Unitarians,

I honestly am disappointed on how hard Unity has made it to do this seemingly simple task.

What I want is a single text field, centered in the exact middle of the screen, with its proportions the same for every android screen resolution, and the text within it centered and the font size changes to accommodate the screen size. This sounds really simple, but 2 hours later I can't do anything. I really hope Unity fixes their GUI soon.

But before that, does anyone know how to do the above?

Thanks, Aman Jha

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

2 Replies

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

Answer by aman_jha · Aug 02, 2014 at 10:22 PM

I figured it out by fiddling with NGUI. I found that I had a free pack of the full version in my unity packages so I imported it and worked with it.

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 zharik86 · Jul 29, 2014 at 06:24 AM

If you need only one text box, use the GUIText component. Set in its parameters alignment on the middle and set transform values (0.5, 0.5, 0). Sets pixelOffset is equal 0 for two value. Now the text will be on the screen middle, but unfortunately Unity isn't able to scale elements under different screen resolutions. Therefore it is necessary to write a small script and to attach it, for example, to MainCamera (write on CSharp):

  //Base value of resolution screen for which the text is made
  public float origW = 1200.0f;
  public float origH = 720.0f;
 
  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
   GUIText[] texts =  FindObjectsOfType(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 = origSizeText * scaleX; //new size font
   }
  }

I hope it will help you.

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 aman_jha · Jul 29, 2014 at 02:43 PM 0
Share

$$anonymous$$aybe I didn't specify it in my question. It isn't a GUIText that I need fixed. I can use those, I'm confused on using the text fields that unity makes me write in the OnGUI thing. Where the user can type in stuff.

avatar image zharik86 · Jul 29, 2014 at 07:08 PM 0
Share

@Yoman For function OnGUI() and text into it use GUI.$$anonymous$$atrix for scaling font size and another elements.

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

C++ windows DLL and Android? 1 Answer

A node in a childnode? 1 Answer

GUI how to make the scrollbar bigger? 1 Answer

Android Textfield locks out input until esc 2 Answers

Create a Button Scrollview 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