- Home /
Detect if dragged over object
Is there a way to detect if the user has been holding down the input button (whether it be a mouse or a touch) and during that time they moved over a gameobject with a boxcollider on it?
Basically I am trying to see if I can start touching outside of the gameobject's bounds and while still touching, drag overtop of the gameobject (kind of like selecting multiple characters in a string with your finder/mouse) and I want the gameobject to then detect "Hey, I see that you started touching somewhere else, but while you were still touching you dragged overtop of me! Now I am going to do something!"
Assu$$anonymous$$g you're using touches try using:
http://docs.unity3d.com/ScriptReference/TouchPhase.html
along with bools (e.g.
if (Input.GetTouch(i).phase == TouchPhase.Began) { move = true; }
else if (Input.GetTouch(i).phase == TouchPhase.$$anonymous$$oved)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
// Physics2D for 2D projects
if (Physics.Raycast (ray, out hit) && hit.GameObject.tag == "ButtonTag")
{ Button$$anonymous$$agic (); }
if
(Physics.Raycast (ray, out hit) && hit.GameObject.tag == "$$anonymous$$oveBtn")
{ move = true; }
else {move = false;}
}
PS: I know it's a bit messy let me know if it just confused you more ^^
Answer by Malleck666 · Jul 06, 2015 at 05:37 AM
Try using...
OnMouseEnter() {
if (Input.GetMouseButtonDown(0)){
// DO SOMETHING
}
}
Your answer
Follow this Question
Related Questions
Input.GetTouch(0).position.x and TouchPhase.Began 1 Answer
Swipe and Hold to move character . 1 Answer
Touch drag objects, raycast cant detect object? 1 Answer
C# Screen.width Touch Input In Multiple Scripts Affect Each Other - Please Help 1 Answer
How to select an object with TOUCH and change its animation 2D 1 Answer