Вот мой рабочий код без ограничения вертикального вращения:
Код: Выделить всё
[SerializeField]
private Camera _camera;
[SerializeField]
private Transform target;
private Vector3 previousPosition;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
previousPosition = _camera.ScreenToViewportPoint(Input.mousePosition);
}
if (Input.GetMouseButton(0))
{
Vector3 direction = previousPosition - _camera.ScreenToViewportPoint(Input.mousePosition);
_camera.transform.position = target.position;
_camera.transform.Rotate(new Vector3(1, 0, 0), direction.y * 180);
_camera.transform.Rotate(new Vector3(0, 1, 0), -direction.x * 180, Space.World);
_camera.transform.Translate(new Vector3(0, 0.3f, -3));
previousPosition = _camera.ScreenToViewportPoint(Input.mousePosition);
}
}
Подробнее здесь: https://stackoverflow.com/questions/725 ... tion-limit
Мобильная версия