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 Zanrok · Oct 10, 2012 at 09:52 PM · 3dtextloops

Replace Text with coresponding 3D Models

So here is my idea but I am not really sure how to implement it. I want to develop a script that evaluates what the user types in a string into a public field or even the Text Mesh component. This script will run through each letter of what was typed and instantiate the corresponding 3D model. So in essence, I can create all the characters of the alphabet in 3D and export them into Unity. When I type into the text field and hit play...the script will display the 3D models of the characters.

Positioning, size and readability don't matter so much here. I just wanted to know if it was possible and maybe some ideas on how to start it.

I am newbie when it comes to C#, but I figured out that you can use something like this to display when a textobject contains a certain string.

 GetComponent<TextMesh>().text = test;
 
 if (test.IndexOf("this") != -1)
         {
             Instantiate(textObj, transform.position, transform.rotation);
             Debug.Log("string contains 'this'");
         }

I know realistically, that I need to do some sort of Loop in order to check each character of the string and then match it to the corresponding 3D Model. Thoughts? Comments? Am I sort of on the right track?

Thanks for reading and for any help or suggestions you might have.

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 Eric5h5 · Oct 10, 2012 at 11:01 PM 0
Share

I'd suggest looking at FlyingText3D, which would simplify things a lot.

avatar image Zanrok · Oct 10, 2012 at 11:08 PM 0
Share

@Eric5h5, I would try something like that if it was free. But without a demo I do not want to spend any money on a plugin. Thanks though.

1 Reply

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

Answer by DaveA · Oct 10, 2012 at 10:01 PM

There are probably many ways to do this, but off the top:

Create an array of GameObjects, sized to 128. Drop your text object models (prefabs) into the slot corresponding to the ascii code in the array. Example: Element 65 would correspond to model 'A'. (note you can make an Editor script to aid this process).

When running, access the string you are converting character-at-a-time with String. Untested:

 var chars : GameObject[]; // assign these inspector or with Editor script
 
 for (int i = 0; i < str.length; i++)
   Instantiate (chars[((int)str[i])], new Vector3(i, 0, 0), Quaternion.identity);
Comment
Add comment · Show 5 · 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 Zanrok · Oct 10, 2012 at 11:07 PM 0
Share

Thank you Dave, I will try to run through the method you suggested. Like i said I am still trying to get my head around C#. It looks like you idea is simple enough... in theory.... Thanks for the help either way, you have given me something to go with!

avatar image Zanrok · Oct 11, 2012 at 09:06 PM 0
Share

Hey Dave, so I have tried various versions of the code you listed trying to get it to function correctly with no success. Right now I am stuck on the very last line, where it Instantiates the GameObject. I don't really understand what you are doing in that last line so any explanation would be very helpful. Currently I am able to successfully log each letter typed in the "string" field but how do I convert each letter to a corresponding ID of the 3D gameObject? Thanks again!

avatar image DaveA · Oct 11, 2012 at 09:13 PM 0
Share

chars[] contains the gameobjects. str[i] is the i'th character in the string. (int)str[i] converts the character (like "A") to a number (like 65). $$anonymous$$aybe you don't need the .ToString() part, try that. I'll edit my answer

avatar image Zanrok · Oct 15, 2012 at 11:18 PM 0
Share

Using a variation of Dave's example code I was able to add 3D letters using a public string variable in the inspector. Thanks Dave! I will try post the exact method I used when it is complete. Currently I am having issues with deleting duplicate letters.

avatar image Zanrok · Oct 15, 2012 at 11:41 PM 0
Share

Here is a part of the script I ended with.

     byte[] ASCIIBytes = Encoding.ASCII.GetBytes(test);

         float po = 0;
         foreach (byte b in ASCIIBytes)
         {
             Debug.Log(test);
       
             // Adds current letter to List and Instantiates letter .obj
             currentLetters.Add((Instantiate(testObj[b], new Vector3(po, 0, 0), Quaternion.Euler(270, -180, 0)) as GameObject));

             testObj[b].transform.tag = "Word";
 
         }

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

11 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

Related Questions

Problem with fonts with ttf format 2 Answers

3D Text Mesh - Display Glitch 0 Answers

i Have AN error when i create assets font editor 0 Answers

3D text face camera 2 Answers

how do I add text to a 3D cube? 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