简体   繁体   English

如何在 Unity 中禁用 UI 多点触控?

[英]How to disable UI multi touch in Unity?

private void Awake()
{
    Input.multiTouchEnabled = false;
}  

public void touch()
{
    Score++;
}

This doesn't work.这行不通。

Touch multiple times at once to increase your score multiple times.一次触摸多次可多次提高分数。 Help me to increment once even with multiple presses.帮助我增加一次,即使多次按下。

Just ignore touches, when finger count is > 1.当手指数大于 1 时,忽略触摸。

if (Input.touchCount == 1)
{
     Score++;
}

This depends a bit on how you detect the touch.这在一定程度上取决于您如何检测触摸。 With multiTouchEnabled set to false, you might still get a MouseDown event or something similar for some other than the first finger.multiTouchEnabled设置为 false 时,您可能仍会收到MouseDown事件或除第一根手指以外的类似事件。 Nevertheless, after a press, you can lock the functionality of increasing your score until you know there is no touch and then unlock it again.然而,在按下后,您可以锁定增加分数的功能,直到您知道没有触摸,然后再次解锁

bool locked = false;

//call this whenever you detect a touch, no matter how
public void Touch() {
 if(!locked){
   locked = true;
   score++; 
 }

void Update(){
  if(Input.touchCount == 0) locked = false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM