Unity indicates extra touch

Hey guys, I’ve got a problem and I just can’t find any relative questions and answers on the internet. I’m just wondering if anybody have the same issue. :neutral:

So that’s the thing - I’ve got a simple code for my android device: when you touch the screen the main camera rotates 90 degrees left (if you touch the left field of the screen) or right (if you touch the right field), BUT sometime (not always) when I touch the screen one time - camera rotates twice, and moreover I’m trying to indicate the number of touches by this code

Debug.Log ("A touch was detected. A number of touches = " + touchCount); //touchCount is my variable

And it says something like:
A touch was detected. A number of touches = 1
A touch was detected. A number of touches = 2
A touch was detected. A number of touches = 4 // here is the wrong number
A touch was detected. A number of touches = 5
A touch was detected. A number of touches = 6
A touch was detected. A number of touches = 8 // here is the wrong number

So you can look at my code below.

var TouchNum:int = 0;
var Direction:int = 0;

function FixedUpdate ()  {

 if(Input.touchCount == 1  Input.GetTouch(0).phase == TouchPhase.Ended  Input.GetTouch(0).position.x < Screen.width/2) 
{
       direction = -1;
	CamRotate();
        Debug.Log ("A touch was detected. A number of touches = " + touchCount);
 }

if(Input.touchCount == 1  Input.GetTouch(0).phase == TouchPhase.Ended  Input.GetTouch(0).position.x > Screen.width/2) 
 {
	direction = 1;
        CamRotate();
        Debug.Log ("A touch was detected. A number of touches = " + touchCount);
 }

 if (Input.touchCount == 2)
 {
	Jump();
 }

}

Here is the CamRotate Function

function CamRotate()
{
  var prevTouch = TouchNum;
  TouchNum += direction;
  if (TouchNum > prevTouch)
  { 
      //rotate camera to the right
  }
  if (TouchNum < prevTouch)
  { 
      //rotate camera to the left
  }

}
if(Input.GetMouseButtonDown(0))
{
    //Do smth
}

Ok, As I can see there is no answer, But I solved this problem.

Somehow Unity executes this condition ( if(Input.touchCount == 1 Input.GetTouch(0).phase == TouchPhase.Ended Input.GetTouch(0).position.x < Screen.width/2)) twice. And both times the coordinates of my touch are the same.

So I’ve just added an extra condition - if PrevTouchX != CurrentTouchX then execute the body. So it works, and if anyone have the same problem - try first to compare coordinates of your touch. That’s it !

What is wrong with my answer? It will indicate only one touch.

It’s not the code issue, I think it’s a device problem - my phone indicates double touch with the same coordinates) So as i fixed my code - it’s working perfectly )