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("五个手指触屏!");

            }

        }
    }
 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值