• 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 bebob235 · Dec 10, 2013 at 10:22 AM · javascript2dtouchdragmouse-drag

I'm not sure how to approach this.

Hello Unity people!

I'm trying to make a game (of course) and the part that I'm working on right now involves the player interacting with it. I have wrote the code for everything until the player has to actually play the game. So- balls are randomly moving around the (2D) board at a constant speed. The player needs to keep the balls from the middle so I wanted to do some type of drag and drop script. What I want to happen is that the player will see the ball coming towards the middle and touch the ball and drag out. Whichever direction that he drags is the new direction for the ball while the speed will stay the same. There are many balls bouncing around in the board so dragging can't effect the other ones.

Some steps in the right direction would be great.

thanks

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 StormSabotage · Dec 10, 2013 at 01:02 PM

If you want to know "how" you can do that:

You will need Collider component in your balls, both for one u want to drag out and for others which moving around. U can do a Raycast from mouse cursor position and check if it collide with your "balls with movement". When u come to middle and take your "special ball to drag" u can just listen to it OnCollisionEnter event and check the name or tag of object, which Collide it, to know if it was one of your "balls with movement". There is one of many ways how to make that. Use Unity Script Reference )

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 bebob235 · Dec 11, 2013 at 06:32 AM 0
Share

thanks for the help!

avatar image
0

Answer by ZaidesA · Dec 10, 2013 at 12:51 PM

You can use OnMouseDrag.

Here is a similar question, hope that helps.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 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

Related Questions

Drag object by Touch quickly 1 Answer

How to drag a GameObject with touch but at a limited speed 1 Answer

* SOLVED * Convert Input.GetAxis("Horizontal") to Touch Drag with Width Control 1 Answer

Simultaneous Touch Drag Controls 0 Answers

Converting screen coordinates to world coordinates 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges