查看: 599|回复: 0
打印 上一主题 下一主题

[其他] 触摸屏滑动的代码

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53488
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-5-29 02:51:23 |只看该作者 |倒序浏览
触摸屏滑动的代码
  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.         }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏1 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-8-6 08:54 , Processed in 0.093129 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部