- Home /
Starting drag onMouseEnter
Hi!, I'm making a game where the goal of a player is to drag an object onto another object using the mouse or touch (All mouse actions are translated into touch actions for mobile).
This is kinda straight forward and was implemented using onMouseDown and onMouseDrag like so:
void OnMouseDown()
{
originalPosition = transform.position;
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);
transform.position = curPosition;
}
I want to add a feature that when positioning the mouse/finger anywhere on the screen, then moving it over one of the objects, the object will be "collected" and dragged with the mouse/finger.
I tried using onMouseEnter and onMouseHover but it didn't work, help will be much appreciated .
Your answer
Follow this Question
Related Questions
Dragging an object by touch? 6 Answers
How to instantiate object at touch position? 3 Answers
How Can I Drag the Object With Touch ? (Mobile) 4 Answers
How to drag a GameObject with touch but at a limited speed 1 Answer
Multiple Touch Drag iOS 0 Answers