- Home /
Detect word clicks on 3Dtext
Hey guys,
Im trying to work out how to write a system where the user can tap/click on a 3Dtext element and then detect which word was clicked on. I'm assuming there is no way of natively doing so. The only ideas i have so far is to attach a box collider, click on it, detect the hit.collider.ClosestPointOnBounds
and work out relatively where the click was based on the amount of characters. Which would mean i need to read the characters, parse them to individual words and determine their seperate bounds. The issue with this is that each character has a different width, and it might also change depending on the distance from the camera.
Any suggestions of a way i could do this?
Another idea i have is to create an editor script where a designer can can type in a sentence, which then parses it into seperate words, giving a 3Dtext object for each word and attaching a seperate box collider per word and then just calling the parent "controller" when an individual word has been pressed.
Thanks
Did you ever find a way to go about this? Looking to experiment with some solutions over the next couple days.
Hey. I ended up writing my own solution for this. I prototyped it just before christmas, so my memory on it is a little sketchy. But from what i could remember i wrote an editor window script that you can insert a string sentence to be printed on screen. The editor script then creates a series of 3DText elements to construct this sentence and space them out etc. The script also attaches a box collider on it and managed these words in an array with a second array with audio clips corrosponding to those words. When a word is tapped on the relative audio file is grabbed from the second array and then gets played and the text colour changed, a coroutine would keep track of the progress of playing the audio file and then change the text colour back to the original. Hope that helps.
Yeah actually that is how I was planning on going about it. I will give it a shot in a couple days, and see how it goes. Thanks
No worries! Let me know how you guy. I'll probably post an answer in the next few days to explain my solution a little better.
I updated my original question here http://answers.unity3d.com/questions/211325/clicking-on-individual-words-in-text-area.html Still haven't totally got it, but getting close. Would love to see how you went about it if you have time to post up your code.