Код: Выделить всё
public Camera cam;
private Vector3 dragOrigin;
public float moveSpeed = 1.0f;
// Update is called once per frame
void Update()
{
DragCamera();
}
private void DragCamera()
{
if (Input.GetMouseButtonDown(0))
{
dragOrigin = cam.ScreenToWorldPoint(Input.mousePosition);
}
if (Input.GetMouseButton(0))
{
Vector3 difference = dragOrigin - cam.ScreenToWorldPoint(Input.mousePosition);
cam.transform.position = Vector2.Lerp(cam.transform.position, cam.transform.position + difference, moveSpeed * Time.deltaTime);
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-unity-2d
Мобильная версия