var e : Event = Event.current;
var xMousePosition = e.mousePosition.x;
var yMousePosition = e.mousePosition.y;
function OnGUI () {
if (Input.GetMouseButton(1))
GUI.Box (Rect (xMousePosition,yMousePosition,120,120), "");
}
i want when i right click it gets the current mouse position at which right clicked and show the GUI box there …can any one help me
function OnGUI () {
if (Input.GetMouseButton(1))
GUI.Box (Rect (Input.mousePosition.x,Input.mousePosition.y,120,120), "");
}
But the box will be open only while you’re holding the right button down - and it will follow the mouse pointer if it moves. If you want the box to appear and remain openned, do the following:
var boxOpen: boolean = false;
var boxPos: Vector3;
function Update () {
if (Input.GetMouseButtonDown(1)){
boxPos.x = Input.mousePosition.x;
// Y runs up to down in GUI, so let's invert it
boxPos.y = Screen.height - Input.mousePosition.y;
boxOpen = true;
}
}
function OnGUI () {
if (boxOpen)
GUI.Box (Rect (boxPos.x,boxPos.y,120,120), "");
}
You must set boxOpen to false to close it.
EDITED: Y runs upside down in GUI system, so it must be inverted (0 is Screen.height)