android - Unity持续触摸检测

标签 android unity-game-engine touch

我在停止屏幕触摸事件时遇到问题,其中有一个按钮,一旦我点击 UI 按钮,它仍然检测到屏幕上的触摸事件,我该如何停止屏幕触摸这样做的事件?提前致谢。

这是我的触摸屏的代码:

for (int i = 0; i < Input.touchCount; i++) {

   if (myTouch [i].phase == TouchPhase.Began) {

   } else if (myTouch[i].phase == TouchPhase.Moved) {

   } else if (myTouch [i].phase == TouchPhase.Ended) {
      // RUN TOUCH FUNCTION HERE
   }
}

在我的按钮上:

public void PauseGame(){

    //DO Pause game here

}

最佳答案

您可以简单地创建 bool 变量,例如将“isTouchActive”设置为 true,而不是在按钮逻辑上更改其状态,例如:
isTouchActive = !isTouchActive;
在触摸逻辑中,只需检查此变量即可:

if(isTouchActive)
{  
 for (int i = 0; i < Input.touchCount; i++) 
 {

   if (myTouch [i].phase == TouchPhase.Began) {

   } else if (myTouch[i].phase == TouchPhase.Moved) {

   } else if (myTouch [i].phase == TouchPhase.Ended) {
      // RUN TOUCH FUNCTION HERE
   }
 }
}

关于android - Unity持续触摸检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32942746/

相关文章:

AndroidViewClient 点击特定的 X,Y 坐标

android - 在文本更改事件之前自动调用 RxAndroid textview 事件

tomcat - 使用 Unity 连接到 Web 服务器

ios - touchesBegan 方法的问题

java - 如何在特定情况下捕获OnTouchEvent?

android - 从 AccountManager 获取基本的谷歌授权 token

android - 方视频1 :1 ration ffmpeg command "Unrecognized option ' ‌​pr‌​eset'"not found at the time of crop video in android?

firebase - 迁移到 Play Install Referrer API Unity3d

android - 尝试使用 soomla iap 购买时谷歌身份验证错误

c# - 接受触摸而不移动鼠标?