Definition
int,int GetGUIImagePosition(string GUIName, string imageName)
Description
This function returns the two-dimensional position of the image imageName 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 images 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 imageName image belongs. You can also use the name “this” for this parameter. In this case, the name “this” refers to the GUI to which the image imageName belongs.
imageName
Specifies the name of the image that belongs to GUIName.
Return Value
Two-dimensional position of the image imageName 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 = GetGUIImagePosition("gui_test_test", "image1") message = string.format("\nGUI image 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 GetGUIImagePosition function returns the 2D position of the “image1” image 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 GetGUIImagePosition2.lua x = 0 y = 0 function OnSelectMouseLButtonDown() x,y = GetGUIImagePosition("this", "BackgroundImg") message = string.format("\nGUI image position is > %d, %d" , x,y) PrintConsole(message) end function OnSelectMouseRButtonDown() end function OnSelectMouseEnter() end
Assume that the above script named GetGUIImagePosition2.lua is attached to a button named “PlayGame” that belongs to the GUI “gui_1”. Also assume that the GUI “gui_1” has an image named “BackgroundImg”. In this case, “this” string in the GetGUIImagePosition function refers to the name “gui_1”. Whenever the user left clicks the “PlayGame” button, we get the position of the image “BackgroundImg” belonging to current GUI, which is GUI “gui_1”. Then we display the result in the console using the PrintConsole function.