Skip to content

Instantly share code, notes, and snippets.

@jonathantsang
Created January 10, 2017 02:33
Show Gist options
  • Save jonathantsang/e265932ee3d20f99f9b31dd8876a148d to your computer and use it in GitHub Desktop.
Save jonathantsang/e265932ee3d20f99f9b31dd8876a148d to your computer and use it in GitHub Desktop.
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