Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 diabloroxx · Sep 07, 2010 at 07:10 PM · gameobjectmousedragresizeedge

Resize / Scale, Drag, Move a Plane at Runtime by Mouse action

Is it possible to find the Coordinates of the mouse with respect to the GameObject (in this case, a PLANE). If it is near the edge, then give the Resize option where you can drag the mouse diagonally to Scale it UP or Down. If the mouse is in Center, then give the option to Drag the object around.

I have the dragging part figured out using the OnMouseOver() , however am trying to detect when the Mouse is near the Edge of the plane.

In short- I want to select a Plane, either move it or resize it based on whether the User clicks in the Center or Edge.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jesse Anders · Sep 07, 2010 at 09:13 PM

Yes, it is possible.

To address the specific question of differentiating between a 'move' operation and a 'resize' operation, you'll want to transform the pick point into the local space of the plane. (Note that, strictly speaking, we're talking about a rectangle here and not an actual plane.)

To transform the point into local space, you can use Transform.InverseTransformPoint(). There are several ways you could then determine whether the point is near an edge. A simple solution would be to compare the absolute values of the transformed point's x and z elements (assuming the plane lies in the XZ plane in local space) to a threshold value. For example, if the plane (rectangle) has an x and z extent of 10, you would consider the point as being close to an edge if abs(p.x) or abs(p.y) is greater than (e.g.) 9. (You can also use this information to determine which edge the point is nearest to.)

Comment
Add comment · Show 2 · 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 diabloroxx · Sep 07, 2010 at 11:11 PM 0
Share

Thanks a lot. Let me try that out. So if I have 10 different planes(rectangles), can I attach the same script to all of them and then have them function the same way? or will I be tied down with 1 single plane and Camera position w.r.t that object.

avatar image Jesse Anders · Sep 08, 2010 at 11:55 AM 1
Share

Assu$$anonymous$$g the implementation is correct, you can attach the same script or scripts to all of the rectangles in your scene. There should be no need to duplicate the functionality on a per-object or per-camera basis.

avatar image
0

Answer by Ben 16 · Sep 28, 2010 at 02:03 PM

Can I ask how you did your resizing, as I am faced with a similar task just now. The way I intend to tackle the identifying of where the user clicks is actually create non rendered game objects around the edges of the object, so that in the corners I can say "scale uniformly" and on the edges "scale in direction (x||y||z)" while if the mouse is over the main game object, drag to move. So I have my concept, just need to work out how to resize an object at runtime based on a mouse drag.

Comment
Add comment · Show 1 · 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 diabloroxx · Oct 01, 2010 at 06:19 PM 0
Share

If you are just looking for resize, you can have a look at some of the Gizmo examples posted by other users. Check this one - http://answers.unity3d.com/questions/5275/how-to-create-handles-like-editor-gizmos-in-runtime

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

No one has followed this question yet.

Related Questions

Dragging a GameObject with mouse 1 Answer

Game Object flies out of screen when dragged 1 Answer

Drag GameObject only in a specific area 1 Answer

Fixing "Drag GameObject with mouse" script 1 Answer

Controlling an animation by dragging a gameObject with the mouse 0 Answers


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