Unity3D 中的触摸和滑动问题

SebGM2018

我有一个游戏,你可以滑动一些东西,然后找到特别的东西。您只需点击它,而不是滑动。为此,我创建了以下代码,但它无法正常工作:

void Update()
 {
     if (Input.touchCount > 0)
     {
         // get the first one
         Touch firstTouch = Input.GetTouch(0);

         // if it began this frame
         if (firstTouch.phase == TouchPhase.Began)
         {
             if (firstTouch.position.x > screenCenter)
             {
                 Anim.SetBool("Swiper", true);
                 print("Swipe");
             }
         }
         else if (firstTouch.phase == TouchPhase.Stationary)
         {
             if (E.FInt == 1)
             {
                 //Sound
                 print("Debugged");
                 SceneManager.LoadScene(Beh.SceneArray[Beh.Counter]);
             }
         }
     }
 }

这里的问题是,即使你只是点击它,它也会执行你滑动时的代码。

Draco18s 不再信任 SE

让我们看看这个部分:

     // if it began this frame
     if (firstTouch.phase == TouchPhase.Began)
     {
         if (firstTouch.position.x > screenCenter)
         {
             Anim.SetBool("Swiper", true);
             print("Swipe");
         }
     }

如果触摸阶段是Began并且触摸在屏幕的右侧,那么显然它是滑动。

不,不,不是。这是一个刚刚开始的接触。它还没有被刷过的机会。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章