Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BrennanVargas1 · Jun 20, 2011 at 04:48 AM · dragdragwindow

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jun 20, 2011 at 05:12 AM 0
Share

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?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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));
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

I want to set mechanics like in this game 'Sand Ball' where you swipe on sand and sand is removed from swiping area? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges