Well i have this script and this is a small version of it.
using UnityEngine;
using System.Collections;
public class Window : MonoBehaviour {
public Rect windowRect2 = new Rect(20, 20, 210, 450);
public bool isPremium == false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(isPremium == true){
windowRect2 = new Rect(20, 20, 260, 450);
}
}
}
I know whats making it wrong its that if the boolean is true that it changes its position and it keeps it there. Is there something i can change the (20, 20, to that will not change the position of it?
PS. The draggable window is connected to another part of coding but i am not showing it in this. The void it is in doing have what it needs to be dragged because if isPremium == false than you can drag it.
Here’s the general algorithm on dragging a “window”:
Upon clicking on the window to start a drag operation:
Get the current position of the cursor and store it in a variable.
Upon moving the mouse while the drag click is still active:
Get the new position of the cursor.
Get the difference vector between the position of the cursor before the drag and the new position.
Move your window by adding the difference vector you obtained from Step 2 to the starting point of the window (top-left for OnGUI() methods, bottom-left for GUIElement objects).
I don’t know if that helps you though, since I can’t follow what you’re trying to do.
Make sure you’ve implemented the window the right way. Some have problems how to use GUI.DragWindow. Just take a look at the documentation.
public Rect windowRect2 = new Rect(20, 20, 210, 450);
void OnGUI()
{
windowRect2 = GUI.Window(0,windowRect2,DrawWindow,"Title");
}
void DrawWindow(int ID)
{
// Draw your window content here
GUI.DragWindow();
// or if you want just the title bar be dragable:
// GUI.DragWindow(new Rect(0, 0, 10000, 20));
}