Created
February 24, 2015 09:33
-
-
Save litvil/19f2caf4d1d8bd87093c to your computer and use it in GitHub Desktop.
Unity3d. Camera touch movement - 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Vector2 worldStartPoint; | |
void Update () { | |
// only work with one touch | |
if (Input.touchCount == 1) { | |
Touch currentTouch = Input.GetTouch(0); | |
if (currentTouch.phase == TouchPhase.Began) { | |
this.worldStartPoint = this.getWorldPoint(currentTouch.position); | |
} | |
if (currentTouch.phase == TouchPhase.Moved) { | |
Vector2 worldDelta = this.getWorldPoint(currentTouch.position) - this.worldStartPoint; | |
Camera.main.transform.Translate( | |
-worldDelta.x, | |
-worldDelta.y, | |
0 | |
); | |
} | |
} | |
} | |
// convert screen point to world point | |
private Vector2 getWorldPoint (Vector2 screenPoint) { | |
RaycastHit hit; | |
Physics.Raycast(Camera.main.ScreenPointToRay(screenPoint), out hit); | |
return hit.point; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment