Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Coleclaw199 · Aug 27, 2021 at 01:12 AM · guiuser interfacedrag-and-dropresizeresizing

How can I resize an image with drag-and-drop?

Before attempting to post this question here, I have spent the past day trying to create a method of resizing an image for my virtual "OS" desktop. The end goal was for me to have resizable windows, but I have seemingly exhausted every possible option that I could think of.

At this point I have a square image with colliders around the outer edges, but I can't seem to figure out how to properly tell if they are being clicked, let alone dragged.

alt text

If anyone has any ideas, I would be very grateful. I try to not ask questions on here if I don't have to, as I don't want to clog it up, but I have legitimately no idea how to proceed.

new-unity-project-10-samplescene-pc-mac-linux-stan.png (14.9 kB)
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 Eno-Khaon · Aug 27, 2021 at 04:55 AM 0
Share

A few details that could use clarification:

You mention that you're making a "virtual OS desktop", and that you're having trouble "resizing an image".

What exactly are you referring to when you say "image" in this context? Do you actually mean an image, as-is, or do you mean something like resizing a window in Windows, for example?

Is all of this done using a (one/multiple) Canvas(es)? Is it just floating GameObjects?

There's a lot of missing context, so the more information you can provide about what you're trying to do and how you've tried to do it, the better.

1 Reply

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

Answer by GeroNL · Aug 27, 2021 at 04:08 AM

Hello, did you mean one handed resizing?


i never do this, but i will giving my idea, onbtndown you save the pos, i wil say it StartPos vector2, and on drag you will measure current pos(click draged) in ondragbtn with StartPos, if the CurPos.x > StartPos ||CurPos.x < StartPos then do resizing of image(you calculated it with your value, you can resizing per value different or divide it to get good resizing) and so on to the y value. and up to let it not resizing anymore.


Hope it help,.

Comment
Add comment · Show 3 · 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 Coleclaw199 · Aug 27, 2021 at 04:36 AM 0
Share

My issue is that, first of all, I can't resize the image via code, as far as I know. Second of all, I don't know how to detect when the player is clicking any of the 4 BoxCollider2Ds that I have on there.

Also, what exactly do you mean by "one-handed resizing"?

Thank you for your help, by the way, I appreciate it. :)

avatar image GeroNL Coleclaw199 · Aug 27, 2021 at 05:10 AM 0
Share

well , on handed resizing cause you resizing something with one hand(in smart phone you can do scaling with two fingers, well should a must say 1 finger resizing, lol, i meshed up)/ by clicking if on pc.


why you cant resize the image?

  // this resizing your btn in btndown
  yourtBtn.gameObject.transform.localScale *= 0.75f;

Resize the game object that on it, all in hierarchy is Gameobject.


To detect 2dRay form touch(if pc by clicking) do like this :

  //ONupdate
  Ray ray = new Ray();
  RaycastHit hit;
  ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  if (Physics.Raycast(ray, out hit))
  {
       if(hit == yourimage that have collider)
       {
            //do something  
       }
  }

do something like tht.


to get first pos you can do it on btndown, your btn down must be have parameter like "PointerEventData eventData", eventData have position, you can use it. onDrag will have too.

avatar image Coleclaw199 GeroNL · Aug 27, 2021 at 08:37 AM 0
Share

You sir, are a genius. You managed to give me an idea to break the mold. So far it's working, but I'll mark it as the solution as I just need to work out a few mathematical kinks and personal errors that happen because me dumb :)

For anyone who reads this, who has the same problem, I did this with buttons around the image.

alt text

There are 8 buttons, of which clicking and dragging the top, bottom, left, or right buttons control one axis of stretch, and clicking and dragging any corner offers dual axis control.

new-unity-project-10-samplescene-pc-mac-linux-stan.png (220.7 kB)

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

205 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resizing GUI position with screen size? 0 Answers

Uncompressed Texture for GUI Doesn't Display 1 Answer

GUI button resizing makes button disappear? 1 Answer

Working health script? 2 Answers

I ask one thing about resizing with different resolution. 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