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 RustyHook · Jul 12, 2014 at 10:15 AM · guiscalescoreguitextscreen resolution

How to make GUI Text Scale to different Resolutions?

Hi, I have a GUI text that needs to be scaled to different sizes depending on the screen, the score transforms and adds +1 each time a object is tapped, this is the score system script ( C# )

 using UnityEngine;
 using System.Collections;
 
 public class Score : MonoBehaviour {
 
     public Transform clicks;
     public GUIText score;
     public bool  clicked = false;
     static int click = 69;
 
     public void  Start (){
 
     }
     
     public void  Update (){
         score.text = " " + click;
 
         if (click == 0)
             Application.LoadLevel("Superman");
 
     }
     
     
     
     void  OnMouseDown (){
         click += -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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sillanstudios · Jul 12, 2014 at 01:16 PM

Hi There, Just un tick the "pixel correct" box. You should be able to scale it with the transform component. It may look a bit blocky so go the where you have stored your font in your project and increase the font size property. Cheers! :D

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 12, 2014 at 10:21 AM

See my pregoing response for scaling GUIText and GUITexture. Or see my second response

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 RustyHook · Jul 12, 2014 at 10:36 AM 0
Share

I used your C# Script and placed it onto the GUIText and this returned. /TextScale.cs(4,6): error CS0116: A namespace can only contain types and namespace declarations

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

$$anonymous$$ost likely you copied, but it isn't clear as well as where. As I understood, you used a script from the second example. I will a little reduce it as GUIText is necessary to you only. (replace all text in your script on written by me):

  using UnityEngine;
  using System.Collections;

  public class TextScale : $$anonymous$$onoBehaviour {
   //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
    }
   }
  }

That's all. Attach this script to any object in scene. For example $$anonymous$$ainCamera.

P.S.: If there are errors, it is possible to receive more detail information.

avatar image
0

Answer by yyamiyyugi · Jul 12, 2014 at 10:38 AM

I use the solution found here

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why this Error when trying to add a score using the new GUI ? 0 Answers

How do I build a GUI that works on different sized screens? 3 Answers

Score going up every second 1 Answer

GUI Problem 1 Answer

GUI Text Score counter 3 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