Hi, all in the title really.
The rectangle keeps staying at (0,0).
Not sure if I’ve done something wrong, or I need to go about it another way…
Thanks in advance,
static Rect myRect;
bool showBuildMenu = false;
void Update(){
RaycastHit rayHit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetButtonDown ("Fire1")) {
if(Physics.Raycast (ray, out rayHit) && rayHit.collider.tag == "Zone"){
Vector2 mousePos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(mousePos);
myRect = new Rect (convertedGUIPos.x, convertedGUIPos.y,120,80);
showBuildMenu = true;
} else {
showBuildMenu = false;
}
}
}
void OnGUI() {
if (showBuildMenu == true) {
GUI.Window (0, myRect ,DoMyWindow, "mywindow");
}
}
void DoMyWindow(int windowID) {
if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
print("Got a click");
if (GUI.Button(new Rect(10, 50, 100, 20), "Hello World2"))
print("Got a click2");
}