Recently wrote a parkour game, summed up under the knowledge Point: O (∩_∩) o~
usingUnityengine;usingSystem.Collections; Public classdemo:monobehaviour{ PublicVector3 Lastmonsedown; /// <summary> ///judging the direction of finger touch/// </summary> /// <returns></returns>Touchdir Gettouchdir () {//record the coordinate point of the first finger click if(Input.getmousebuttondown (0) ) {Lastmonsedown=input.mouseposition; } //uicamera.hoveredobject prevent Ngui click through problems if(Input.getmousebuttonup (0) && Uicamera.hoveredobject = =NULL) { //end coordinate-start coordinateVector3 mouseUp =input.mouseposition; Vector3 Touchoffset= MouseUp-Lastmonsedown; //swipe over 50 pixels to calculate the correct slide if(Mathf.abs (Touchoffset.x) > -|| Mathf.abs (TOUCHOFFSET.Y) > -) { if(Mathf.abs (Touchoffset.x) > Mathf.abs (TOUCHOFFSET.Y) && touchoffset.x >0) { returnTouchdir.right; } Else if(Mathf.abs (Touchoffset.x) > Mathf.abs (TOUCHOFFSET.Y) && Touchoffset.x <0) { returnTouchdir.left; } Else if(Mathf.abs (Touchoffset.x) < Mathf.abs (TOUCHOFFSET.Y) && touchoffset.y >0) { returnTouchdir.top; } Else if(Mathf.abs (Touchoffset.x) < Mathf.abs (TOUCHOFFSET.Y) && Touchoffset.y <0) { returnTouchdir.bottom; } } Else { returnTouchdir.none; } } returnTouchdir.none; }}/// <summary>///the direction of the touch/// </summary> Public enumtouchdir{None, left, right, Top, Bottom}
The direction of Unity finger touch (one-handed)