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
2
Question by Sonaten · Nov 27, 2012 at 01:52 PM · c#colliderdynamic3dtext

Dynamic Collidersize based on string length for '3d Text'?

Problem: I am looking to get the length of a '3d Text' object, and to adjust a box collider based on this lenght.

Context: I have implemented a modified version of This Drag-And-Drop-Script, that have been working fine whilst using a simple box collider. What I need is a dynamic manipulation of the box collider based on the length of my 3d Text object.

I am spawning individual words in a sentence, as a list of strings that each hold one word, and I want these to be draggable. Of course with the best possible interaction, being that the collider fits the word somewhat perfectly. And the spacing between the words fitting that of a normal sentence (this should be easily solveable when I get a fitting collider).

Approaches so far: I have tried using the .Length property, however this does not take the different "length" of individual letters into account. I could take the largest posible length of a letter, the smallest posible, or an estimated average of the length of all letters in the alphabet and use this as a factor for the .Length property. These will however result in weird spacing between individual words, as these are to be placed based on the same value as the colliders length.

MeshCollider wasn't a solution either as the 3d Text does not have an actual mesh.

Thanks in advance.

EDIT:

The solution resulted in the wanted collider and wanted spacing, as illustrated on the picture below.

alt text

(The words are in danish, so don't mind the meaning of them.)

worspacing small.png (205.6 kB)
Comment
Add comment · Show 4
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 Sonaten · Nov 28, 2012 at 07:53 AM 0
Share

Gonna check out renderer.bounds.size as suggested by Shrandis and Jim. Hope this is what I'm looking for so far.

avatar image Sonaten · Nov 28, 2012 at 09:00 AM 0
Share

It was indeed what I needed, one up to both Shrandis and Jim. And, as expected, I will be able to place the individual words with the right spacing based upon the same method.

avatar image Sonaten · Nov 28, 2012 at 09:16 AM 1
Share

It even works better than expected. Would really like to 1up more than once. Thanks a lot.

avatar image Nethekurse · Apr 14, 2014 at 12:41 PM 0
Share

Hi can you post the solution for creating individual 3d Text with collider for each word, im making a 2d game that the user click and drag some words to complete the phrase, but im having trouble to set the collders in the right position, could you help me?

2 Replies

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

Answer by Shrandis · Nov 27, 2012 at 02:33 PM

You can set the collider's size to renderer's bounds. Example:

 BoxCollider col = (BoxCollider)collider;
 col.size = renderer.bounds.size;

However, the collider's position won't fit the text unless the text's anchor is middle-center. So if your text has another anchor, you'll need to change the collider's position too. Depending on what you need you might want to just set the collider's X or Y or Z instead of all 3 of them.

Please don't forget to click the checkmark & thumbs up if my answer answered your question and feel free to add comments if you have questions.

Comment
Add comment · Show 1 · 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 Sonaten · Nov 28, 2012 at 08:29 AM 0
Share

;) Not going to forget. I'll will check if this is the solution I need. I'm used to the "answers" Q&A format from stackoverflow, and do very much intent to give credit where it is due.

avatar image
1

Answer by loopyllama · Nov 27, 2012 at 02:35 PM

try fetching the renderer.bounds of a word then setting the box collider using the bounds info

maybe that will be accurate enough for your needs

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

12 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

[4.6 - UI] Changing the text component via script? 6 Answers

BoxCollider Overlap OnTriggerEnter Problem 1 Answer

Drag a sprite by its 2D Polygon Collider component 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