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 Case23 · Jun 28, 2010 at 11:06 PM · scaleguitextfont

Changing GUIText.font on runtime

So i realy try hard to find a solution for this and dont understand why this failure happens.

I creating a GUIText and add it to a GameObjekt.

On each Update i calculate the distance between the GO and the camera, and based to this distance i change my font of the GUIText.

Im using 10 different and added all to a List

GameObject label = new GameObject("label"); // Gui Text GUIText guiT = label.AddComponent<GUIText>(); // I stored all my Fonts in a List in another class so do not // wonder where it got instantiatet guiT.font = FontAssets.univerRoman[0]; guiT.material.color = new Color(1.0f, 1.0f, 1.0f); guiT.text = "name";

void Update() { int distanceToCamera = Vector3.Distance(label.transform.position,cam.transform.position);

 int scale = Mathf.FloorToInt((99 - _distanceToCamera)/10);
 guiT.font = FontAssets.univerRoman[scale];

}

All my text got realy messed up, and it looks like the size of the texture the text is rendered on is the wrong size.

EDIT: So after spending several hours with no real result i tryed 3dtext, and instantiate it in this way.

GameObject _label3d = new GameObject("label3d"); TextMesh _guiT3D = _label3d.AddComponent<TextMesh>(); MeshRenderer _ren = _label3d.AddComponent<MeshRenderer>();

_label3d.renderer.material = FontAssets.refFontAssets.univerRoman_22_mat;

_guiT3D.text = _name; _guiT3D.font = FontAssets.refFontAssets.univerRoman_22; _guiT3D.font.material = FontAssets.refFontAssets.univerRoman_22_mat; _guiT3D.renderer.material = FontAssets.refFontAssets.univerRoman_22_mat;

_ren.material = FontAssets.refFontAssets.univerRoman_22_mat; _ren.material.color = Color.white;

And still i have the same result. The scale of the Text material does not fit tothe scale of the textSize.

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
1

Answer by Tetrad · Jun 28, 2010 at 11:25 PM

Your GUIText object also has a renderer in it which is going to need to be updated to the right material.

Although are you just making it smaller for things that are further away? Why not just use 3D text?

Comment
Add comment · Show 8 · 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 Case23 · Jun 28, 2010 at 11:33 PM 0
Share

I think i will use pretty allot of them. Like i think at least 10000. Im not sure about the performance, but i believe rendering a 2d text is cheaper than a 3d text. Or do i think wrong?

avatar image Tetrad · Jun 28, 2010 at 11:53 PM 0
Share

Well I always say write first and optimize later.

avatar image Case23 · Jun 28, 2010 at 11:56 PM 0
Share

Okay, if i try " _label.renderer.material = FontAssets.univerRoman[scale].material; " it says label does not have a renderer attached. If i try to attach one, Unity says a Renderer can not be attached. :/

avatar image Eric5h5 · Jun 29, 2010 at 12:14 AM 0
Share

@Case23: 2D text and 3D text are the same thing: they are both textures on quads. If anything, I'd expect 3D text to be slightly cheaper. In either case, 10000 of them will kill any computer.

avatar image Mike 3 · Jun 29, 2010 at 12:14 AM 0
Share

try guiT.material

Show more comments

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

No one has followed this question yet.

Related Questions

Are Real Vector Fonts Possible in Unity? 3 Answers

Changing the font size of GUIText (on Unity iPhone)? 1 Answer

Unity3d font with strikethrough 2 Answers

How to display Greek alphabets 0 Answers

Font Scaling Issues 2 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