Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Created March 23, 2026 14:32
Show Gist options
  • Select an option

  • Save TheCuttlefish/64ab470bcede226ddb4b4ce661a1354d to your computer and use it in GitHub Desktop.

Select an option

Save TheCuttlefish/64ab470bcede226ddb4b4ce661a1354d to your computer and use it in GitHub Desktop.
Pan with Right click
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