- Home /
Location of a char in a String
I'm currently having trouble figuring out how to replace certain text in my GUI with a button. I'm parsing it out correctly, and getting the correct dimensions, but I can't for the life of me figure out how to find the X and Y coordinate of the first character that I'm parsing out. Any help or point in the right direction would be greatly appreciated.
Resolved~ Result: http://dl.dropbox.com/u/18867763/Unity/StoryTeller/WebPlayer/WebPlayer.html Code
var buttonLocationRect = Engine.Skin.textArea.GetCursorPixelPosition(Engine.BoxRect), new GUIContent(infoString), infoString.IndexOf('<'));
What exactly are you trying to do? This GUI, is it a GUIText or some GUI system object (GUI.Label, GUI.Button etc.)? And about which X and Y coordinate are you talking? Screen coordinates? Finding the position of some single character in Unity seems impossible to me.
Answer by jahroy · Dec 01, 2011 at 11:15 PM
Is that what these functions are for?
http://unity3d.com/support/documentation/ScriptReference/GUIStyle.GetCursorStringIndex.html
http://unity3d.com/support/documentation/ScriptReference/GUIStyle.GetCursorPixelPosition.html
I don't know the answer to that question.
It sounds like these functions might do what you want, but the documentation is so brief it's hard to tell.
Good job, @jahroy! Now finding the position of any character seems possible to me - at least in the GUI system (not so easy, given the laconic description in the docs).
If these do work, and I'll try them as soon as I can, it'll be a lot simpler than the way I had figured out. Thanks.
Edit: Yes! It works exactly how I need it!
That's great news. I was hoping that's what they did, but haven't gotten a chance to play with them yet.
Cheers for another reason to love Unity Answers... You just paste a link up and get immediate proof of concept!
Your answer
![](https://koobas.hobune.stream/wayback/20220613061701im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
UnitySerializer Delete Saved Games 0 Answers
How do I center the gui created by this script? 0 Answers
Score Help (Im new) 1 Answer
Switching lines on gui text area 1 Answer