Created
January 10, 2017 02:33
-
-
Save jonathantsang/e265932ee3d20f99f9b31dd8876a148d to your computer and use it in GitHub Desktop.
This file contains 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
public class dragcontroller : MonoBehaviour { | |
public Camera cam; | |
Vector2 initial; | |
Vector2 end; | |
// Update is called once per frame | |
void Update () { | |
checkdrag (); | |
} | |
void Start() { | |
initial = Input.mousePosition; | |
end = Input.mousePosition; | |
} | |
void checkdrag(){ | |
end = Input.mousePosition; | |
if ((initial != end) && (Input.GetButton("Fire1") == true)) { | |
Debug.Log ("Moved"); | |
Vector3 difference = initial - end; | |
difference.x *= 0.1f; | |
difference.y *= 0.1f; | |
Vector3 newpos = cam.transform.position + difference; | |
Debug.Log ("Diff: " + difference); | |
Debug.Log ("New Pos: " + newpos); | |
cam.transform.position = newpos; | |
} | |
Debug.Log ("Nope"); | |
initial = end; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment