Hello,
I’m having trouble making a GUI.Window appear where I clicked on the screen.
Here is what I’m doing right now:
Player clicks on a blue circle on the map, which instantiates a prefab. This prefab has a script with OnGUI that loads a GUI.Window. The only thing I’m using to position the window on the screen is Input.mousePosition.
Using the screen captures below the first image shows when I click on the blue circle it shows the position is x:283, y:322. The x is always correct but the Y is always below for this circle. For other circles on the map it also may appear above where clicked.
In the second screen capture if I drag the window to where I think it should appear it shows the new position of the window is x:283, y:145. The prefab game object that is instantiated is set to a position of 0,0,0 (if that matters).
Code I’m using on the blue circles to instantiate the prefab (abWindow is a public variable assigned to the prefab)
function OnMouseUp () {
Instantiate(abWindow, transform.position, transform.rotation);
}
In the prefab I’m using this code:
function Awake () {
var screenPos : Vector3 = Input.mousePosition;
print("Screen Position:" + screenPos);
objectWindow = Rect(screenPos.x,screenPos.y, winWidth,200);
}
function OnGUI () {
objectWindow = GUILayout.Window (windowid, objectWindow, handleWindow, "Selected Object");
}
function handleWindow (windowID : int) {
GUILayout.Label("Window is at: " + objectWindow.x + " : " + objectWindow.y);
if (GUI.Button(Rect(100, 150, 100, 25), "Close") ) {
Destroy(this.gameObject);
}
GUI.DragWindow();
}
Thanks for any help,
Brent