Advertisement
Sabotender

most simple map panner

Feb 18th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. public class MapCamera : MonoBehaviour {
  2.     public float panSpeed = 1;
  3.  
  4.     private bool isDragging;
  5.     private Vector2 lastMousePos;
  6.    
  7.     // Update is called once per frame
  8.     void Update () {
  9.         //When clicking the mouse down
  10.         if(Input.GetMouseButtonDown(0)) {
  11.             isDragging = true;
  12.             lastMousePos = Input.mousePosition;
  13.         }
  14.  
  15.         //While dragging
  16.         if(Input.GetMouseButton(0)) {
  17.             transform.Translate(new Vector3(Input.mousePosition.x - lastMousePos.x, 0, Input.mousePosition.y - lastMousePos.y) * Time.deltaTime * panSpeed * -1);
  18.             lastMousePos = Input.mousePosition;
  19.         }
  20.  
  21.         //When releasing the mouse
  22.         if(Input.GetMouseButtonUp(0)){
  23.             isDragging = false;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement