Definition
int,int GetGUITextPosition(string GUIName, string textName)
Description
This function returns the two-dimensional position of the text textName of GUI GUIName relative to the lower left part of the screen as two x, y values. You can view and copy the name of the GUIs and their texts in the Script Utility section (Tools > Script Editor > Tools > Script Utility) or the Prefabs and GUIs section of the current VScene.
Parameters
GUIName
Specifies the name of the GUI to which the textName text belongs. You can also use the name “this” for this parameter. In this case, the name “this” refers to the GUI to which the text textName belongs.
textName
Specifies the the name of the text that belongs to GUIName.
Return Value
Two-dimensional position of the text textName of GUI GUIName relative to the lower left part of the screen as two x, y values.
Example 1
x = 0 y = 0 function OnSelectMouseLButtonDown() x,y = GetGUITextPosition("gui_test_test", "text1") message = string.format("\nGUI text position is > %d, %d" , x,y) PrintConsole(message) end function OnSelectMouseRButtonDown() end function OnSelectMouseEnter() end
Assume that this script is attached to a button named ShowPosition that belongs to a GUI named gui_position. In this case, whenever you left click on the ShowPosition button, the GetGUITextPosition function returns the 2D position of the “text1” text from the GUI named “gui_test_test”. This script then displays the x and y positions on the console.
Example 2
--Name of script is GetGUITextPosition2.lua x = 0 y = 0 function OnSelectMouseLButtonDown() x,y = GetGUITextPosition("this", "text1") message = string.format("\nGUI text position is > %d, %d" , x,y) PrintConsole(message) end function OnSelectMouseRButtonDown() end function OnSelectMouseEnter() end
Assume that the above script named GetGUITextPosition2.lua is attached to a button named “PlayGame” that belongs to the GUI “gui_1”. Also assume that the GUI “gui_1” has a text named “text1”. In this case, “this” string in the GetGUITextPosition function refers to the name “gui_1”. Whenever the user left clicks the “PlayGame” button, we get the position of the text “text1” belonging to current GUI, which is GUI “gui_1”. Then we display the result in the console using the PrintConsole function.