There are two scripts, in one using the IBeginDragHundler interface, swipes are read, and the rotation vector is equated to evenData.delta
.
public class CameraControl : MonoBehaviour, IDragHandler, IBeginDragHandler
{
[HideInInspector] public static Vector2 napravlenie;
[SerializeField] private float sensivity = 6;
public static bool Moved = false;
public void OnBeginDrag(PointerEventData eventData)
{
Moved = true;
napravlenie = eventData.delta * sensivity * Time.deltaTime; ;
}
public void OnDrag(PointerEventData eventData) { }
}
And the second script, which is directly responsible for turning the camera.
[SerializeField] private Transform Camera;
private float AnglRot;
private void Update()
{
if (CameraControl.Moved == true) { Rotation(); }
}
public void Rotation()
{
AnglRot = Mathf.Clamp(AnglRot - CameraControl.napravlenie.y, -90, 90);
Camera.localRotation = Quaternion.Euler(AnglRot, 0, 0);
transform.Rotate(transform.up, CameraControl.napravlenie.x);
}
As a result, the code does not rotate the camera. I tried comparing the delta in x and y and changing the vector, but that didn’t help either. Help solve the problem and fix the errors.
New contributor
Георгий is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.