Definition
SetGUITextPosition(string GUIName, string textName, int x, int y)
Description
This function sets 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.
x, y
Specify 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.
Example 1
function Init() SetGUITextPosition("gui_SampleGUI17_MainMenu", "text1", GetScreenWidth() / 2, GetScreenHeight() / 2) end function Update() end
In this example, SetGUITextPosition function sets the 2D position of the text “text1” from the GUI named “gui_SampleGUI17_MainMenu” to (screen width / 2) and (screen height / 2), respectively.
Example 2
--Name of script is SetGUITextPosition2.lua function OnSelectMouseLButtonDown() SetGUITextPosition("this", "text1", GetScreenWidth() / 2, GetScreenHeight() / 2) end function OnSelectMouseRButtonDown() end function OnSelectMouseEnter() end
Assume that the above script named SetGUITextPosition2.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 SetGUITextPosition function refers to the name “gui_1”. Whenever the user left clicks the “PlayGame” button, we set the X and Y position of the text “text1” belonging to current GUI, which is GUI “gui_1”, to (screen width / 2) and (screen height / 2), respectively.