• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Need urgent help with dynamic font not working on Mac! 1 Answer

GuiText for Unity 4 dynamic scaling issue mobile 0 Answers

Is there a way to measure the pixel with/height of a string with a given font? 2 Answers

GUIText - how to set letter spacing? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges