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 Lunestia · Jan 13, 2014 at 07:20 PM · move an objectpause menuclick to move

Move objects with mouse while paused (2D)

How would I be able to make specific objects in the game world (marked with its own material) move using the mouse while in game?

Comment
Add comment · Show 2
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 robertbu · Jan 13, 2014 at 07:22 PM 0
Share

I'm not sure what part of this problem you are asking for help with. I assume that you paused the game by setting Time.timeScale = 0.0? If so you will still get Update() calls and can use any drag and drop code to move your object that does not depend on Time.deltaTime (which is most drag and drop code). There are a number of posts on UA with drag and drop code.

avatar image Lunestia · Jan 15, 2014 at 01:00 AM 0
Share

I need to know how to do the two together. I've got pausing worked out so far.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Jan 15, 2014 at 01:46 AM

Any drag and drop code you find (and it has been posted to UA many times), that use OnMouseDown() rather than raycasting will work in 2D. Raycasting solutions would need a bit of change for 2D. Here is one link. The script will need to be attached to each object you want to be draggable:

http://answers.unity3d.com/questions/486097/mouse-clicking-on-the-plane-and-drag-to-other-posi.html

Note if you only want to only have it draggable if the game is paused, then you can add something like this to the top of the OnMouseDown() callback:

 if (Time.timeScale > 0.01) return;


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 Lunestia · Jan 16, 2014 at 01:00 AM 0
Share

I can't seem to find any answers which use On$$anonymous$$ouseDown rather than Raycasting. Also, with the one you linked, It is only working on the X axis and is ignoring collision detection.

avatar image robertbu · Jan 16, 2014 at 03:52 AM 0
Share

The code at the link will work for most common and some uncommon situations. The only situation I can think of that it will not work for is the camera looking down on the XZ plane. Note I tested it with a standard 2D setup with a Sprite and with the camera facing positive Z and it worked fine for tracking the mouse on both 'X' and 'Y'.

Collision detection is another story. Nothing in your original question suggested that collision detection was a requirement. In order to make collision detection work you may have to go to a 2D rewrite of the standard DragRigidbody.js script. Available:

 Assets > Import Package > Scripts 

The 2D stuff is new, so I'm still learning about how certain problems are solved.

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

18 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

Related Questions

How to move a rigid body when you click on it 1 Answer

Why do my GUI elements move when exported to Android? 1 Answer

How can i make an object move from a OnMouseDown? 1 Answer

Predefine player movement in game? 0 Answers

My character isn't moving 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