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 Stealthygolem · Nov 09, 2014 at 02:12 AM · instantiatechildtextmeshduplicateborder

Smart way to add border to a text mesh in a 2d environment

Hello! I am making a text mesh in my game project which is a damage number, it looks very good at the moment. But, I would love to add a black border around the text mesh, to add to the pixely style of the game. I'm thinking that I would just instantiate a textmesh child object of the text mesh that is slightly bigger and being behind the original text mesh object. Any smart way to do this?

Here is my code of assigning the textmesh value:

     public float hpLost;    
 
         void TakeDamage() {
             TextMesh text = (TextMesh)thing.GetComponent(typeof(TextMesh));
             text.text = "-" + hpLost.ToString("F1");
             thing.rigidbody2D.AddRelativeForce(randomDirection);
         }
     //hpLost is assigned damageDealt from another script.

If you think there is lacking some vital information, please just ask, but there's not much more to the textmesh :)

Comment
Add comment · Show 3
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 Stealthygolem · Nov 16, 2014 at 05:23 PM 0
Share

I'm still looking for an answer to this :)

avatar image SaraCecilia · Nov 17, 2014 at 04:04 PM 0
Share

What happened when you tried out your solution?

avatar image Stealthygolem · Nov 20, 2014 at 01:57 PM 0
Share

This solution is working fine for what it is meant to do, which is to create a text mesh with the value I assign it, which is hpLost (amount of health points lost). The new solution I am looking for, is to add a black border around this text-mesh. It would look much more esthetically pleasing in my game.

Changing the size of a text-mesh works on the individual letters of the text mesh, so, for me to be able to create a pseudo black border looking thing, I could add 5 text-meshes with black color, just behind the original text-mesh with small difference in placement in the x and y axis. This would give the illusion of a black border. I believe this will work (having played around with it a while), but I don't like the thought of instantiating 6 objects every time this method gets called.

1 Reply

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

Answer by Stealthygolem · Nov 27, 2014 at 09:15 PM

I found a solution that I consider is temporary, but it does look much better, and I only instantiate two more objects.

This is how my method now looks like. I added two other duplicates of the first textmesh and changed their color to black, and as you can see in the script I offset the Z-value a bit, to add to the illusion that it has a border. These two only add borders for the left and right side of the mesh in theory. But, it does look quite good, and I could make it look even better by just adding more some more if I would find it desirable. The consideration would be performance, of course!

     void TakeDamage() {
         objectSpeed = 60f;
         Vector2 randomDirection = Random.insideUnitCircle * objectSpeed;
 
 
         GameObject dicks = Instantiate(textMeshObject,transform.position,Quaternion.identity) as GameObject;
         TextMesh text = (TextMesh)dicks.GetComponent(typeof(TextMesh));
         text.text = "-" + hpLost.ToString("F1");
         dicks.rigidbody2D.AddRelativeForce(randomDirection);
 
         GameObject dicks2 = Instantiate(textMeshObject2, new Vector3 (transform.position.x+0.02f,
                                                                       transform.position.y,
                                                                       transform.position.z),Quaternion.identity) as GameObject;
         TextMesh text2 = (TextMesh)dicks2.GetComponent(typeof(TextMesh));
         text2.text = "-" + hpLost.ToString("F1");
         dicks2.rigidbody2D.AddRelativeForce(randomDirection);
 
         GameObject dicks3 = Instantiate(textMeshObject3, new Vector3 (transform.position.x-0.02f,
                                                                       transform.position.y,
                                                                       transform.position.z),Quaternion.identity) as GameObject;
         TextMesh text3 = (TextMesh)dicks3.GetComponent(typeof(TextMesh));
         text3.text = "-" + hpLost.ToString("F1");
         dicks3.rigidbody2D.AddRelativeForce(randomDirection);
     }

Any critique on this or a better idea is still rather highly appreciated.

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

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

Related Questions

How do I get the global position 2 Answers

Network.Instantiate fired from client AND server 1 Answer

UnityException: Transform child out of bounds. 1 Answer

Instantiate UI object as child of panel relative to panel's location 1 Answer

How can I make a game object follow an instantiated game object? 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