unity 三指,四指,五指触屏

 /// <summary>
    /// 三只手指触屏,向左,向右滑动
    /// </summary>
    public void threeFinger()
    {

        if (Input.touchCount == 3)
        {

            if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began || Input.GetTouch(2).phase == TouchPhase.Began)
            {
                //记录手指刚触碰的位置
                oldPosition1 = Input.GetTouch(0).position;
                oldPosition2 = Input.GetTouch(1).position;
                oldPosition3 = Input.GetTouch(2).position;
            }


            // 三只手指触摸类型都为移动触摸
            if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved || Input.GetTouch(2).phase == TouchPhase.Moved)
            {
                //// 记录当前三点触摸点的位置
                var tempPosition1 = Input.GetTouch(0).position;
                var tempPosition2 = Input.GetTouch(1).position;
                var temPosition3 = Input.GetTouch(2).position;

                float xOne = tempPosition1.x - oldPosition1.x;
                float xTwo = tempPosition2.x - oldPosition2.x;
                float xThree = temPosition3.x - oldPosition3.x;

                if (xOne > 0 || xTwo > 0 || xThree > 0)
                {
                    print("三只手指触屏!向右滑动!");

                    Mune.gameObject.SetActive(false);

                }

                if (xOne < 0 || xTwo < 0 || xThree < 0)
                {
                    print("三只手指触屏!向左滑动!");

                    Mune.gameObject.SetActive(true);

                }


            }


        }

    }

    /// <summary>
    /// 四只手指触屏
    /// </summary>
    public void fourFinger()
    {
        if (Input.touchCount == 4)
        {
            if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began || Input.GetTouch(2).phase == TouchPhase.Began || Input.GetTouch(3).phase == TouchPhase.Began)
            {
                //记录手指刚触碰的位置
                //记录手指刚触碰的位置
                oldPosition1 = Input.GetTouch(0).position;
                oldPosition2 = Input.GetTouch(1).position;
                oldPosition3 = Input.GetTouch(2).position;
                oldPosition4 = Input.GetTouch(3).position;
            }

            if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved || Input.GetTouch(2).phase == TouchPhase.Moved || Input.GetTouch(3).phase == TouchPhase.Moved)
            {


                //// 记录当前三点触摸点的位置
                var tempPosition1 = Input.GetTouch(0).position;
                var tempPosition2 = Input.GetTouch(1).position;
                var temPosition3 = Input.GetTouch(2).position;
                var temPosition4 = Input.GetTouch(3).position;


                float yOne = tempPosition1.y - oldPosition1.y;
                float yTwo = tempPosition2.y - oldPosition2.y;
                float yThree = temPosition3.y - oldPosition3.y;
                float yFour = temPosition4.y - oldPosition4.y;


                if (yOne > 0 || yTwo > 0 || yThree > 0 || yFour > 0)
                {
                    print("四个手指触屏!向上滑动!");


                }

                if (yOne < 0 || yTwo < 0 || yThree < 0 || yFour < 0)
                {
                    print("四个手指触屏!向下滑动!");

                }

            }

        }
    }


    /// <summary>
    /// 五只手指触屏
    /// </summary>
    public void fiveFinger()
    {
        if (Input.touchCount == 5)
        {
            if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(1).phase == TouchPhase.Began || Input.GetTouch(2).phase == TouchPhase.Began || Input.GetTouch(3).phase == TouchPhase.Began || Input.GetTouch(4).phase == TouchPhase.Began)
            {
                //记录手指刚触碰的位置

            }

            if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved || Input.GetTouch(2).phase == TouchPhase.Moved || Input.GetTouch(3).phase == TouchPhase.Moved || Input.GetTouch(4).phase == TouchPhase.Moved)
            {
                //记录手指移动
                print("五个手指触屏!");

            }

        }
    }
 

猜你喜欢

转载自blog.csdn.net/weixin_42399500/article/details/83307739