Touch.phase
is updated every frame, so you have to check it within the Update()
method.
FixedUpdate()
is only called every x
frames (fixed framerate), that's the reason you are missing some of the touch phases.
Pregunta
In Unity, I am attempting to use Touch
.
I am having non-stop issues with it and have decided to just try and get something simple working first.
Whenever i press the screen, i am expecting Touch.phase
to return TouchPhase.Began
every time. However, it will sometimes return TouchPhase.Stationary
when touching the screen for the first time. I have also noticed that it will sometimes not call TouchPhase.Ended
or TouchPhase.Canceled
when the touch has left the screen. What am i doing wrong?
Here is my very simple code:
void FixedUpdate() {
if(Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
switch(touch.phase) {
case TouchPhase.Began:
Debug.Log("Began: " + touch.figerId);
break;
case TouchPhase.Stationary:
Debug.Log("Stationary");
break;
case TouchPhase.Moved:
Debug.Log("Moved");
break;
case TouchPhase.Canceled:
Debug.Log("Canceled");
break;
case TouchPhase.Ended:
Debug.Log("Ended");
break;
default:
Debug.Log("Default");
break;
}
}
}
Solución
Touch.phase
is updated every frame, so you have to check it within the Update()
method.
FixedUpdate()
is only called every x
frames (fixed framerate), that's the reason you are missing some of the touch phases.