- Home /
Why wont my dragable window move?
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.
It doesn't help mush when you have problems with your GUI window and ins$$anonymous$$d of the window code you post code that blocks the movement...
Are you sure that you use GUI.Window the right way?
Answer by BrennanVargas1 · Jun 21, 2011 at 08:50 AM
I figured out what i could do... in the area in the update function i changed
windowRect2 = new Rect(20, 20, 260, 450);
to
windowRect2.width = 260;
Answer by Dreamblur · Jun 20, 2011 at 05:17 AM
Here's the general algorithm on dragging a "window":
Upon clicking on the window to start a drag operation: 1. Get the current position of the cursor and store it in a variable.
Upon moving the mouse while the drag click is still active: 1. Get the new position of the cursor. 2. Get the difference vector between the position of the cursor before the drag and the new position. 3. 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.
Answer by Bunny83 · Jun 20, 2011 at 05:18 AM
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));
}
Your answer
Follow this Question
Related Questions
Move a tile (sprite) with drag and drop in Unity 2D 0 Answers
Multitouch drag object 0 Answers
When is the OnDrop method called? IDragHandler 1 Answer
Drag and jump mechanics? 2 Answers