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 slayer29179 · Jul 20, 2014 at 03:43 PM · sprite3d textsign

Resize sprite to 3D text

Hello all! I have been messing with Unity's new 2D system and I am trying to make a simple sign.

When the player walks past the sign I currently have a sprite and 3D text that appears above it.

For example, when the user walks past the first sign it will appear above a background sprite and 3D text with the sentence "Press 'space' to jump".

alt text

The entire sentence can be changed to anything from the lines of "Press 'left shift' to fire", "Press 'e' to fire" or "Stars can be collected to increase your power levels.". So they do have various lengths.

The users can change the controls too so the images can't be designed in an image editor.

My question is how do I resize the background so it matches the text.

How would I go around this? The only thing I could think, would be to get the individual size of the font letters and increase it from there but it seems a bad way. Is this the only way or is there another way I could use it? I would prefer not to use GUI.Label

Any ideas?

Thanks

proof.png (17.2 kB)
Comment
Add comment · Show 2
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 z3nth10n · Jul 20, 2014 at 03:57 PM 0
Share

You mean fit the text to the sign?

avatar image slayer29179 · Jul 20, 2014 at 04:08 PM 0
Share

Yes but I don't want the text to shrink or anything, I'de rather fit the sign to the text.

1 Reply

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

Answer by robertbu · Jul 20, 2014 at 04:25 PM

Getting the exact size of TextMesh is difficult. There are many posts on the issue. But for what you want, I think you can get away with using the renderer.bounds of the TextMesh. While it can be done with a sprite, for this purpose, I recommend you use a Quad instead. A Quad makes the calculations simpler. Just use a shader like Unlit/Texture with your background as the texture. An example:

  • Create a TextMesh/3D Text object

  • Set the Anchor to the middle center

  • Create a Quad game object

  • Make the Quad a child

  • Set the Quad position to (0,0,0)

  • Put your material on the Quad

  • Attach the following script to the Quad

  • Drag and drop the Text mesh object in the Hierarchy to the 'tm' variable in the script.


    pragma strict

    public var tm : TextMesh; public var xScaleFactor : float = 1.1; public var yScaleFactor : float = 1.03;

    function Update() { var x = tm.renderer.bounds.size.x xScaleFactor; var y = tm.renderer.bounds.size.y yScaleFactor; transform.localScale = Vector3(x,y,1); }

Note if you want to use a Sprite, you will need to get the Sprite.bounds when the scale is (1,1,1) and then scale based on these values. A Quad makes it easy since the size of a Quad with a scale of (1,1,1) is (1,1,1).

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 slayer29179 · Jul 20, 2014 at 04:56 PM 0
Share

Thank you for your answer! It worked! Just trying to make the texture brighter and make it work for labels with \n in them. Thanks!

avatar image robertbu · Jul 20, 2014 at 05:27 PM 0
Share

Forgot to mention, the code above scales every frame. You may want to modify what you do so that the scale is only recalculated when the string changes.

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

23 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 avatar image

Related Questions

Render sprite only behind mesh? 0 Answers

2D sprite character movement 3 Answers

Translucent sprites appear solid 0 Answers

Sprite disappears in front of background 1 Answer

How to kill a bird if it falling too fast? 1 Answer


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