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
}
}