I'm attempting to make specific words in a GUI.Window click activated (text message appears in window, user clicks on one specific word, and an action happens). I've recently found the GUISettings.doubleClickSelectsWord option, but no reference to exactly how it works or how to use it.
How would I use this to enable click activation of text in the GUI.Window. Then, how do I reference in the script which word was clicked so I can make a specific action happen?
Answer by Sebas
Feb 21, 2010 at 03:38 AM
I haven't dealt with GUISettings.doubleClickSelectsWord yet, but I suspect that it won't do what you're after. It's used for text fields where the user enters text. Double-clicking on the word would highlight this word just like in a text editor.
I'd probably go for GUI.button and use the words that you need as texture. If you then click on the word, the button registers a click and you can trigger stuff. That would fairly resemble what you're after. Not perfect, but probably more suitable then a text field.
If double-clicking word in the text field selects the text word, how do you access that word in the script, or is there a way? I would love to hear form someone that has used this command too.
The text field is still intended for the user to manipulate the string. I doubt it's useful for displaying a string and having the user click on something. From the documentation you can only access the complete string of the text field, not the "highlighted" substring. If somebody has experience with using a text field for such purpose, I'd be keen to hear that as well.
Answer by Ashkan_gc
Jun 13, 2010 at 11:52 AM
unity's GUI is a litle different from what you see in other GUI packages. you can get the click event of a button easily or you can use toolbars or selection grids but if you need to get the selected word in a textfield it's not easy. you should use GUIUtility and GUI classes with Event class to work with GUIs in advanced. there are two problems. 1 the documentation of GUIUtility is not complete by no means and getting the info about the text in a textfield needs much more effort. you should opentype library and know the font well to understand the size of the texture for some word and ... don't try it :)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
No one has followed this question yet.
Text and texture in GUI?
GUI & GUI Text Disappear When Publishing
Elements in draggable window do not remain fixed [SOLVED]
Closing window inside the window