Created
March 23, 2026 14:32
-
-
Save TheCuttlefish/64ab470bcede226ddb4b4ce661a1354d to your computer and use it in GitHub Desktop.
Pan with Right click
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
| using UnityEngine; | |
| public class CamDrag : MonoBehaviour | |
| { | |
| bool isDragging = false; | |
| Vector3 mousePos; | |
| Vector3 clickedPos; | |
| void Update() | |
| { | |
| if (Input.GetMouseButtonDown(1)) | |
| { | |
| clickedPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); | |
| isDragging = true; | |
| } | |
| if (Input.GetMouseButtonUp(1)) | |
| { | |
| isDragging = false; | |
| } | |
| if (isDragging) | |
| { | |
| mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); | |
| transform.position -= (mousePos - clickedPos); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment