Find GUIlayout.Button position on mouse click - in flexible space Unity2d
Hi ppl,
Im kinda new to unity and Im actually trying to make a game for kids with dyslexia. Basically it shows a word in the middle of the screen seperated by dots which they can click to draw lines under the syllables. Is there a way to get the position of the clicked GUIlayout.Button or index the GUIlayout.Buttons in some way so I can access their position? I need to draw another texture starting at their position and I need to check their position/index for the syllable check. Or is there a completely different way to make this work?
This is what it looks like :
public void ButtonClicked () {
if (GUILayout.Button(".")) {
Vector3 dot = transform.position;
Debug.Log(dot);
}
public void Punctuation (string word) {
char [] wordArray = word.ToCharArray();
//GUI Layout Function with 1 dot in front of every upcoming word
ButtonClicked();
foreach(char c in wordArray) {
GUILayout.Label(c.ToString());
ButtonClicked();
}
}
UILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if(boxcheck1 == true) {
GUI.Label(new Rect(lineStartPosX,lineStartPosY+50,200,100), curve);
}
ScaledPunctuation("Druckerei");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndArea();
}
question.png
(413.8 kB)
Comment
Why are you not using Unity UI? You can reach components transform values. OnGUI is obsolete.
thank you for the reply I will check some tutorials
Your answer
![](https://koobas.hobune.stream/wayback/20220612073731im_/https://answers.unity.com/themes/thub/images/avi.jpg)