Home > Back-end >  How to disable UI multi touch in Unity?
How to disable UI multi touch in Unity?

Time:05-25

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.

CodePudding user response:

Just ignore touches, when finger count is > 1.

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

CodePudding user response:

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. 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;
}
  • Related