纳金网

标题: 触摸屏滑动的代码 [打印本页]

作者: 烟雨    时间: 2015-5-29 02:51
标题: 触摸屏滑动的代码
触摸屏滑动的代码
  1. if (Input.GetMouseButtonDown(0))
  2.         {
  3.             began = Input.mousePosition;
  4.             isTouch = true;
  5.         }
  6.         else if (Input.GetMouseButton(0))
  7.         {
  8.             Vector2 mouseUp = Input.mousePosition;
  9.             Vector2 touchOffset = mouseUp - began;
  10.             if ((Mathf.Abs(touchOffset.x) > 50 || Mathf.Abs(touchOffset.y) > 50 && isTouch))
  11.             {
  12.                 if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x > 0)
  13.                 {
  14.                     isTouch = false;
  15.                     MoveRight();
  16.                     if (hasMove)
  17.                     {
  18.                         RandomCard();
  19.                     }
  20.                 }

  21.             }
  22.             else if ((Mathf.Abs(touchOffset.x) > 50 || Mathf.Abs(touchOffset.y) > 50 && isTouch))
  23.             {
  24.                 if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x < 0)
  25.                 {
  26.                     isTouch = false;
  27.                     MoveLeft();
  28.                     if (hasMove)
  29.                     {
  30.                         RandomCard();
  31.                     }
  32.                 }

  33.             }
  34.             else if ((Mathf.Abs(touchOffset.x) > 50 || Mathf.Abs(touchOffset.y) > 50 && isTouch))
  35.             {
  36.                 if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.y > 0)
  37.                 {
  38.                     isTouch = false;
  39.                     MoveUp();
  40.                     if (hasMove)
  41.                     {
  42.                         RandomCard();
  43.                     }
  44.                 }

  45.             }
  46.             else if ((Mathf.Abs(touchOffset.x) > 50 || Mathf.Abs(touchOffset.y) > 50 && isTouch))
  47.             {
  48.                 if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.x < 0)
  49.                 {
  50.                     isTouch = false;
  51.                     MoveDown();
  52.                     if (hasMove)
  53.                     {
  54.                         RandomCard();
  55.                     }
  56.                 }

  57.             }

  58.         }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5