void WindowFunction(int windowID) { GUI.Label(new Rect(20, 20, 100, 50), windowText); Vector2 pos = cursorController.GetCursorPosition(); if (windowExpandable) { var testRect = new Rect(10, 70, 100, 100); GUI.Button(testRect, "Sphere Left"); testRect = new Rect(testRect.x + windowRect.x, testRect.y + windowRect.y, testRect.width, testRect.height); if (testRect.Contains(pos) && cursorController.CursorClicked()) //if cursor over button and clicked { GameObject temp = GameObject.Find("TestSphere"); Vector3 vec = temp.transform.position; vec.x -= 0.1f; temp.transform.position = vec; } } var testRect2 = new Rect(150, 0, 50, 50); GUI.Button(testRect2, "X"); testRect2 = new Rect(testRect2.x + windowRect.x, testRect2.y + windowRect.y, testRect2.width, testRect2.height); if (testRect2.Contains(pos) && cursorController.CursorClicked()) //if cursor over button and clicked { showWindow = false; } }