Unity Finger-touch direction (one-handed)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.