- Home /
How to get the individual characters of a TextMesh?
Hello, I want to make a very simple effect with my text were all the letters in a text move randomly. I saw that if you use the TextMesh component to render your text, it cuts every character in your text into individual rectangles, is there a way I can get those rectangles so that I can move them around?
Thank you.
Answer by Noah Dyer · Feb 18, 2015 at 10:48 PM
You cannot access the individual characters in a single text mesh as individual objects and manipulate their transforms.
To accomplish what you want, I would do 1 of 2 things:
1) If I want the moving to be fluid, I would have each letter be a separate gameObject/TextMesh component, and create a class to hold the intended phrase, the letters of the phrase as separate gameobjects, and animate the gameobjects as desired.
2) If by move randomly you mean some kind of scrambling, and the scrambling can happen in flash, you could just change textMeshComponent.text in an update;
The first option seems overcomplicated since depending on the font size I will have to calculate the spacing between letters..I am still trying to get the mesh of the teshmesh..thank you anyways.
The answer is correct, even if you don't like it ;) Please mark it as such, though you are certainly not obligated to use my workarounds, just trying to be helpful.
Unity simply creates a billboard based on the information you supply to text mesh. Once you get it back, it doesn't even know where an individual character is in the billboard, much less does it know and give you power to manipulate the billboard in a way that can be accessed on a per character basis.
To get the functionality you want without managing multiple text meshes as I've suggested, you would have to create your own class to replace Text$$anonymous$$esh, which would first need to handle the job of building individual character billboards from scratch based on font info and the supplied string (what Text$$anonymous$$esh does now for free), and stores each character's billboard in a way that allows you to easily and intuitively manipulate the individual characters as desired (what you want, but Text$$anonymous$$esh cannot be made to do). That seems overcomplicated.
Your answer
Follow this Question
Related Questions
UI Text compression on android 1 Answer
Replacing transparency of text with a solid color? 1 Answer
Layout group children adjust to content 1 Answer
Why does my game look different in Bluestacks then it does in unity? 1 Answer
UI Text.LineSpacing doesn't work when the Text has only one line ? 1 Answer