Hi,
I would like to make the camera slide a little bit more when the touch ends. With this code, the effect works, but sometimes it stops right after the second attempt. The camera is supposed to slide every time the touch has moved and ends, but it sometimes stops for an unknown reason. Would someone have any idea why?
if (Input.touchCount > 0 ){
if ( Input.GetTouch(0).phase == TouchPhase.Began ) {
//_doLongMove = false;
}
if ( Input.GetTouch(0).phase == TouchPhase.Moved ) {
// Get movement of the finger since last frame
touchDeltaPosition = Input.GetTouch(0).deltaPosition;
float speedDrag = 0.2f;
transform.Translate (-touchDeltaPosition.x * speedDrag, 0, -touchDeltaPosition.y * speedDrag);
}
if ( Input.GetTouch(0).phase == TouchPhase.Ended ) {
speed = 0.3f;
_doLongMove = true;
}
}
if ( _doLongMove ) {
doLongMove();
}
void doLongMove(){
float slowDown = 0.01f;
float force = 1.5f;
if ( speed > 0 ){
speed -= slowDown;
}
if ( speed < 0 ) {
speed = 0;
_doLongMove = false;
}
transform.Translate (-touchDeltaPosition.x * force * speed, 0, -touchDeltaPosition.y * force * speed);
}
EDIT:
I also tried this, but it stops as well, sometimes 3 times in a row, then it works fine :
if ( wasDragging && Input.touchCount == 0 ){
speed=0.3f;
_doLongMove = true;
wasDragging = false;
}
if ( _doLongMove ) {
doLongMove();
}
Thanks