- Home /
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
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 )
Answer by ZaidesA · Dec 10, 2013 at 12:51 PM
You can use OnMouseDrag.
Here is a similar question, hope that helps.
Your answer
Follow this Question
Related Questions
Drag object by Touch quickly 1 Answer
How to drag a GameObject with touch but at a limited speed 1 Answer
Simultaneous Touch Drag Controls 0 Answers
Converting screen coordinates to world coordinates 1 Answer
Touch drag 2D object in x axis 1 Answer