Skip to content

Instantly share code, notes, and snippets.

@sylistine
Created February 1, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sylistine/50f5a28ea4430f333980 to your computer and use it in GitHub Desktop.
Save sylistine/50f5a28ea4430f333980 to your computer and use it in GitHub Desktop.
bool handlingInput = false;
void Update ()
{
if(!handlingInput)
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
handlingInput = true;
StartCoroutine(HandleTouch());
}
}
IEnumerator HandleTouch()
{
Touch touch = Input.GetTouch(0);
while (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if(touch.phase == TouchPhase.Moved)
{
Vector3 cameraRelativeDeltaPosition = screenXY2CameraXZ(touch.deltaPosition);
playerOffset.x = playerOffset.x - cameraRelativeDeltaPosition.x;
playerOffset.z = playerOffset.z - cameraRelativeDeltaPosition.z;
}
yield return new WaitForEndOfFrame();
touch = Input.GetTouch(0);
}
handlingInput = false;
yield return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment