How to get my GUI.Window to appear at the mouse position?

Hello all, i’m trying to make a simple window pop-up at the place i have my mouse over when i do a click. From what i know i can only make a window that appears at a specific position on the game window. Is there a way of getting it to appear at the mouse position when there is a click? Any hints, tips or tricks apreciated.
Cheers.

track your mouse position
mousePos= Vector3(Input.mousePosition.x,-(Input.mousePosition.y-Screen.height),0);

enter mousePos.x and mousePos.y as the 2 first parameters of you Rect…

if you want it only on Input.GetMouseButtonDown(0) then make to float vars and change their value to the mousePos.x and y after the Input.

var popUp.x=0.0;
var popUp.y=0.0;
function OnGUI()
{
var mousePos= Vector3(Input.mousePosition.x,-(Input.mousePosition.y-Screen.height),0);

if(Input.GetMouseButtonDown(0))
{
popUp.x=mousePos.x;
popUp.y=mousePos.y;
GUI.Box(Rect(popUp.x, popUp.y, 50,50);
}
}

Got it to work, thanks for the tips. Needed a little tweaking for what i had in mind but tottaly helped out :slight_smile:

You should use Event.current.mousePosition inside OnGUI, which returns correct coordinates that do not need to be converted. Input.mousePosition is not intended for OnGUI.

–Eric